Completed
Push — master ( 60f5be...0d3c0c )
by Kamil
24:02
created

CompositeMethodsResolver::supports()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Shipping\Resolver;
13
14
use Sylius\Component\Registry\PrioritizedServiceRegistryInterface;
15
use Sylius\Component\Shipping\Model\ShippingSubjectInterface;
16
17
/**
18
 * @author Mateusz Zalewski <[email protected]>
19
 */
20
class CompositeMethodsResolver implements MethodsResolverInterface
21
{
22
    /**
23
     * @var PrioritizedServiceRegistryInterface
24
     */
25
    private $resolversRegistry;
26
27
    /**
28
     * @param PrioritizedServiceRegistryInterface $resolversRegistry
29
     */
30
    public function __construct(PrioritizedServiceRegistryInterface $resolversRegistry)
31
    {
32
        $this->resolversRegistry = $resolversRegistry;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getSupportedMethods(ShippingSubjectInterface $shippingSubject)
39
    {
40
        foreach ($this->resolversRegistry->all() as $resolver) {
41
            if ($resolver->supports($shippingSubject)) {
42
                return $resolver->getSupportedMethods($shippingSubject);
43
            }
44
        }
45
46
        return [];
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function supports(ShippingSubjectInterface $subject)
53
    {
54
        foreach ($this->resolversRegistry->all() as $resolver) {
55
            if ($resolver->supports($subject)) {
56
                return true;
57
            }
58
        }
59
60
        return false;
61
    }
62
}
63