Completed
Push — 1.3.3 ( 8b370b )
by Kamil
86:08 queued 74:03
created

PromotionRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A findActiveByChannel() 0 16 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
declare(strict_types=1);
13
14
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
15
16
use Doctrine\ORM\EntityManager;
17
use Doctrine\ORM\Mapping;
18
use Sylius\Bundle\PromotionBundle\Doctrine\ORM\PromotionRepository as BasePromotionRepository;
19
use Sylius\Component\Channel\Model\ChannelInterface;
20
use Sylius\Component\Core\Repository\PromotionRepositoryInterface;
21
use SyliusLabs\AssociationHydrator\AssociationHydrator;
22
23
class PromotionRepository extends BasePromotionRepository implements PromotionRepositoryInterface
24
{
25
    /**
26
     * @var AssociationHydrator
27
     */
28
    private $associationHydrator;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function __construct(EntityManager $entityManager, Mapping\ClassMetadata $class)
34
    {
35
        parent::__construct($entityManager, $class);
36
37
        $this->associationHydrator = new AssociationHydrator($entityManager, $class);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function findActiveByChannel(ChannelInterface $channel): array
44
    {
45
        $promotions = $this->filterByActive($this->createQueryBuilder('o'))
46
            ->andWhere(':channel MEMBER OF o.channels')
47
            ->setParameter('channel', $channel)
48
            ->addOrderBy('o.priority', 'DESC')
49
            ->getQuery()
50
            ->getResult()
51
        ;
52
53
        $this->associationHydrator->hydrateAssociations($promotions, [
54
            'rules',
55
        ]);
56
57
        return $promotions;
58
    }
59
}
60