Passed
Push — master ( 63b45b...921011 )
by Petr
04:21
created

LinksCollectionDTO   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 18 5
1
<?php
2
3
namespace AppBundle\Form\Event;
4
5
use Symfony\Component\Validator\Constraints as Assert;
6
use Symfony\Component\Validator\Context\ExecutionContextInterface;
7
8
/**
9
 * @author Vehsamrak
10
 */
11
class LinksCollectionDTO
12
{
13
14
    /** @var array */
15
    public $links;
16
17
    /**
18
     * @Assert\Callback
19
     */
20 3
    public function validate(ExecutionContextInterface $context)
21
    {
22 3
        if (empty($this->links)) {
23 1
            $context->buildViolation('Parameter is mandatory: links.')->addViolation();
24
        }
25
26 3
        if (!is_array($this->links)) {
27 1
            $context->buildViolation('Links must be an array.')->addViolation();
28
        } else {
29 2
            foreach ($this->links as $linkKey => $link) {
30 2
                $url = $link['url'] ?? null;
31
32 2
                if (!$url) {
33 2
                    $context->buildViolation(sprintf('Parameter is mandatory: links[%s][url].', $linkKey))->addViolation();
34
                }
35
            }
36
        }
37 3
    }
38
}
39