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

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.  * @method void       set(string $key, Error $entity)
  6.  * @method Error[]    getIterator()
  7.  * @method Error[]    getElements()
  8.  * @method Error|null get(string $key)
  9.  * @method Error|null first()
  10.  * @method Error|null last()
  11.  */
  12. class ErrorCollection extends Collection
  13. {
  14.     /**
  15.      * @param Error $error
  16.      */
  17.     public function add($error): void
  18.     {
  19.         $this->set($error->getId(), $error);
  20.     }
  21.     public function blockOrder(): bool
  22.     {
  23.         foreach ($this->getIterator() as $error) {
  24.             if ($error->blockOrder()) {
  25.                 return true;
  26.             }
  27.         }
  28.         return false;
  29.     }
  30.     public function getErrors(): array
  31.     {
  32.         return $this->filterByErrorLevel(Error::LEVEL_ERROR);
  33.     }
  34.     public function getWarnings(): array
  35.     {
  36.         return $this->filterByErrorLevel(Error::LEVEL_WARNING);
  37.     }
  38.     public function getNotices(): array
  39.     {
  40.         return $this->filterByErrorLevel(Error::LEVEL_NOTICE);
  41.     }
  42.     public function getPersistent(): self
  43.     {
  44.         return $this->filter(function (Error $error) {
  45.             return $error->isPersistent();
  46.         });
  47.     }
  48.     public function filterByErrorLevel(int $errorLevel): array
  49.     {
  50.         return $this->fmap(static function (Error $error) use ($errorLevel): ?Error {
  51.             return $errorLevel === $error->getLevel() ? $error null;
  52.         });
  53.     }
  54.     public function hasLevel(int $errorLevel): bool
  55.     {
  56.         foreach ($this->getIterator() as $element) {
  57.             if ($element->getLevel() === $errorLevel) {
  58.                 return true;
  59.             }
  60.         }
  61.         return false;
  62.     }
  63.     public function getApiAlias(): string
  64.     {
  65.         return 'cart_error_collection';
  66.     }
  67.     protected function getExpectedClass(): ?string
  68.     {
  69.         return Error::class;
  70.     }
  71. }