vendor/sylius/sylius/src/Sylius/Component/Shipping/Checker/ShippingMethodEligibilityChecker.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Component\Shipping\Checker;
  12. use const E_USER_DEPRECATED;
  13. use Sylius\Component\Shipping\Model\ShippingMethodInterface;
  14. use Sylius\Component\Shipping\Model\ShippingSubjectInterface;
  15. @trigger_error(sprintf('The "%s" class is deprecated since Sylius 1.8, use "%s" instead.''Sylius\Component\Shipping\Checker\ShippingMethodEligibilityChecker''Sylius\Component\Shipping\Checker\Eligibility\CompositeShippingMethodEligibilityChecker'), E_USER_DEPRECATED);
  16. /**
  17.  * @deprecated since Sylius 1.8. Use Sylius\Component\Shipping\Checker\Eligibility\CompositeShippingMethodEligibilityChecker instead
  18.  *
  19.  * @psalm-suppress DeprecatedInterface
  20.  */
  21. final class ShippingMethodEligibilityChecker implements ShippingMethodEligibilityCheckerInterface
  22. {
  23.     public function isEligible(ShippingSubjectInterface $shippingSubjectShippingMethodInterface $shippingMethod): bool
  24.     {
  25.         if (!$category $shippingMethod->getCategory()) {
  26.             return true;
  27.         }
  28.         $numMatches $numShippables 0;
  29.         foreach ($shippingSubject->getShippables() as $shippable) {
  30.             ++$numShippables;
  31.             if ($category === $shippable->getShippingCategory()) {
  32.                 ++$numMatches;
  33.             }
  34.         }
  35.         return match ($shippingMethod->getCategoryRequirement()) {
  36.             ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_NONE => === $numMatches,
  37.             ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ANY => $numMatches,
  38.             ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ALL => $numShippables === $numMatches,
  39.             default => false,
  40.         };
  41.     }
  42. }