Completed
Pull Request — master (#129)
by Łukasz
03:26
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Validator;
4
5
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidator;
8
9
final class ChannelWithGivenCodeDoesNotExistsValidator extends ConstraintValidator
10
{
11
    /**
12
     * @var ChannelRepositoryInterface
13
     */
14
    private $channelRepository;
15
16
    /**
17
     * @param ChannelRepositoryInterface $channelRepository
18
     */
19
    public function __construct(ChannelRepositoryInterface $channelRepository)
20
    {
21
        $this->channelRepository = $channelRepository;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function validate($token, Constraint $constraint)
28
    {
29
        if (null === $this->channelRepository->findOneByCode($token)) {
30
            $this->context->addViolation($constraint->message);
31
        }
32
    }
33
}
34