Completed
Push — 1.5-symfony-insights ( c13c26 )
by Kamil
05:55
created

ChannelDefaultLocaleEnabledValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 13 3
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\Validator\Constraints;
15
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Symfony\Component\Validator\Constraint;
18
use Symfony\Component\Validator\ConstraintValidator;
19
use Webmozart\Assert\Assert;
20
21
final class ChannelDefaultLocaleEnabledValidator extends ConstraintValidator
22
{
23
    public function validate($channel, Constraint $constraint): void
24
    {
25
        /** @var ChannelDefaultLocaleEnabled $constraint */
26
        Assert::isInstanceOf($constraint, ChannelDefaultLocaleEnabled::class);
27
28
        /** @var ChannelInterface $channel */
29
        Assert::isInstanceOf($channel, ChannelInterface::class);
30
31
        $defaultLocale = $channel->getDefaultLocale();
32
        if ($defaultLocale !== null && !$channel->hasLocale($defaultLocale)) {
33
            $this->context->buildViolation($constraint->message)->atPath('defaultLocale')->addViolation();
34
        }
35
    }
36
}
37