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

ChannelDefaultLocaleEnabledValidator::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 2
nop 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
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