vendor/shopware/core/Checkout/Cart/Error/ErrorCollection.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart\Error;
  3. use Shopware\Core\Framework\Struct\Collection;
  4. /**
  5.  * @extends Collection<Error>
  6.  */
  7. class ErrorCollection extends Collection
  8. {
  9.     /**
  10.      * @param Error $error
  11.      */
  12.     public function add($error): void
  13.     {
  14.         $this->set($error->getId(), $error);
  15.     }
  16.     public function blockOrder(): bool
  17.     {
  18.         foreach ($this->getIterator() as $error) {
  19.             if ($error->blockOrder()) {
  20.                 return true;
  21.             }
  22.         }
  23.         return false;
  24.     }
  25.     public function getErrors(): array
  26.     {
  27.         return $this->filterByErrorLevel(Error::LEVEL_ERROR);
  28.     }
  29.     public function getWarnings(): array
  30.     {
  31.         return $this->filterByErrorLevel(Error::LEVEL_WARNING);
  32.     }
  33.     public function getNotices(): array
  34.     {
  35.         return $this->filterByErrorLevel(Error::LEVEL_NOTICE);
  36.     }
  37.     public function getPersistent(): self
  38.     {
  39.         return $this->filter(function (Error $error) {
  40.             return $error->isPersistent();
  41.         });
  42.     }
  43.     public function filterByErrorLevel(int $errorLevel): array
  44.     {
  45.         return $this->fmap(static function (Error $error) use ($errorLevel): ?Error {
  46.             return $errorLevel === $error->getLevel() ? $error null;
  47.         });
  48.     }
  49.     public function hasLevel(int $errorLevel): bool
  50.     {
  51.         foreach ($this->getIterator() as $element) {
  52.             if ($element->getLevel() === $errorLevel) {
  53.                 return true;
  54.             }
  55.         }
  56.         return false;
  57.     }
  58.     public function getApiAlias(): string
  59.     {
  60.         return 'cart_error_collection';
  61.     }
  62.     protected function getExpectedClass(): ?string
  63.     {
  64.         return Error::class;
  65.     }
  66. }