Completed
Push — master ( 55daec...2d65d3 )
by Kamil
18:26
created

ActivePromotionsByChannelProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPromotions() 0 11 2
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\Core\Provider;
13
14
use Sylius\Component\Core\Model\OrderInterface;
15
use Sylius\Component\Core\Repository\PromotionRepositoryInterface;
16
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
17
use Sylius\Component\Promotion\Provider\PreQualifiedPromotionsProviderInterface;
18
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
19
20
/**
21
 * @author Mateusz Zalewski <[email protected]>
22
 */
23
class ActivePromotionsByChannelProvider implements PreQualifiedPromotionsProviderInterface
24
{
25
    /**
26
     * @var PromotionRepositoryInterface
27
     */
28
    private $promotionRepository;
29
30
    /**
31
     * @param PromotionRepositoryInterface $promotionRepository
32
     */
33
    public function __construct(PromotionRepositoryInterface $promotionRepository)
34
    {
35
        $this->promotionRepository = $promotionRepository;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getPromotions(PromotionSubjectInterface $subject)
42
    {
43
        if (!$subject instanceof OrderInterface) {
44
            throw new UnexpectedTypeException($subject, OrderInterface::class);
45
        }
46
47
        $channel = $subject->getChannel();
48
        $promotions = $this->promotionRepository->findActiveByChannel($channel);
49
50
        return $promotions;
51
    }
52
}
53