ContentItemMatrixValidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 36
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 18 4
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
namespace Zicht\Bundle\PageBundle\Validator\Constraints;
7
8
use Symfony\Component\Translation\TranslatorInterface;
9
use Symfony\Component\Validator\Constraint;
10
use Symfony\Component\Validator\ConstraintValidator;
11
12
/**
13
 * Class ContentItemMatrixValidator
14
 *
15
 * @package Zicht\Bundle\PageBundle\Validator\Constraints
16
 */
17
class ContentItemMatrixValidator extends ConstraintValidator
18
{
19
    /**
20
     * ContentItemMatrixValidator constructor.
21
     *
22
     * @param TranslatorInterface $translator
23
     */
24
    public function __construct(TranslatorInterface $translator)
25
    {
26
        $this->translator = $translator;
0 ignored issues
show
Bug Best Practice introduced by
The property translator does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
    }
28
29
    /**
30
     * Validate
31
     *
32
     * @param mixed $value
33
     * @param Constraint $constraint
34
     */
35
    public function validate($value, Constraint $constraint)
36
    {
37
        $matrix = $value->getContentItemMatrix();
38
39
        if (null !== $matrix) {
40
            foreach ($value->getContentItems() as $i => $contentItem) {
41
                $type = get_class($contentItem);
42
43
                if (!in_array($contentItem->getRegion(), $matrix->getRegions($type))) {
44
                    $this->context->addViolationAt(
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Valida...rface::addViolationAt() has been deprecated: since version 2.5, to be removed in 3.0. Use {@link Context\ExecutionContextInterface::buildViolation()} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

44
                    /** @scrutinizer ignore-deprecated */ $this->context->addViolationAt(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
45
                        'contentItems[' . $i . ']',
46
                        $this->translator->trans(
47
                            "content_item.invalid.region.type.combination",
48
                            array(
49
                                '@region' => $contentItem->getRegion(),
50
                                '@type' => $type
51
                            ),
52
                            'validators'
53
                        )
54
                    );
55
                }
56
            }
57
        }
58
    }
59
}
60