vendor/shopware/core/Checkout/Cart/Tax/Struct/TaxRuleCollection.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart\Tax\Struct;
  3. use Shopware\Core\Framework\Struct\Collection;
  4. /**
  5.  * @extends Collection<TaxRule>
  6.  */
  7. class TaxRuleCollection extends Collection
  8. {
  9.     /**
  10.      * @param TaxRule $taxRule
  11.      */
  12.     public function add($taxRule): void
  13.     {
  14.         $this->set($this->getKey($taxRule), $taxRule);
  15.     }
  16.     /**
  17.      * @param string|int $key
  18.      * @param TaxRule    $taxRule
  19.      */
  20.     public function set($key$taxRule): void
  21.     {
  22.         parent::set($this->getKey($taxRule), $taxRule);
  23.     }
  24.     public function removeElement(TaxRule $taxRule): void
  25.     {
  26.         $this->remove($this->getKey($taxRule));
  27.     }
  28.     public function exists(TaxRule $taxRule): bool
  29.     {
  30.         return $this->has($this->getKey($taxRule));
  31.     }
  32.     public function get($taxRate): ?TaxRule
  33.     {
  34.         $key = (string) $taxRate;
  35.         if ($this->has($key)) {
  36.             return $this->elements[$key];
  37.         }
  38.         return null;
  39.     }
  40.     public function merge(self $rules): self
  41.     {
  42.         $new = new self($this->elements);
  43.         $rules->map(
  44.             function (TaxRule $rule) use ($new): void {
  45.                 if (!$new->exists($rule)) {
  46.                     $new->add($rule);
  47.                 }
  48.             }
  49.         );
  50.         return $new;
  51.     }
  52.     public function highestRate(): ?TaxRule
  53.     {
  54.         return $this->reduce(function ($result$item) {
  55.             return $result === null || $item->getTaxRate() > $result->getTaxRate() ? $item $result;
  56.         });
  57.     }
  58.     public function getApiAlias(): string
  59.     {
  60.         return 'cart_tax_rule_collection';
  61.     }
  62.     protected function getExpectedClass(): ?string
  63.     {
  64.         return TaxRule::class;
  65.     }
  66.     protected function getKey(TaxRule $element): string
  67.     {
  68.         return (string) $element->getTaxRate();
  69.     }
  70. }