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

ChannelWithGivenCodeDoesNotExistsValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
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 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 6 2
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