ConstraintCollection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 52
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 6 1
A add() 0 6 1
A addCollection() 0 6 2
A assertConstraintInstance() 0 9 2
1
<?php
2
namespace Boekkooi\Bundle\JqueryValidationBundle\Validator;
3
4
use Boekkooi\Bundle\JqueryValidationBundle\Exception\InvalidArgumentException;
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Symfony\Component\Validator\Constraint;
7
8
/**
9
 * @author Warnar Boekkooi <[email protected]>
10
 */
11
class ConstraintCollection extends ArrayCollection
12
{
13
    /**
14
     * {@inheritDoc}
15
     *
16
     * @param Constraint $value A Constraint instance
17
     */
18 1
    public function set($key, $value)
19
    {
20 1
        $this->assertConstraintInstance($value);
21
22 1
        parent::set($key, $value);
23 1
    }
24
25
    /**
26
     * {@inheritDoc}
27
     *
28
     * @param Constraint $value A Constraint instance
29
     */
30 7
    public function add($value)
31
    {
32 7
        $this->assertConstraintInstance($value);
33
34 2
        return parent::add($value);
35
    }
36
37
    /**
38
     * Adds a constraint collection at the end of the current set by appending all
39
     * constraint of the added collection.
40
     *
41
     * @param ConstraintCollection $collection A ConstraintCollection instance
42
     */
43 1
    public function addCollection(ConstraintCollection $collection)
44
    {
45 1
        foreach ($collection as $constraint) {
46 1
            $this->add($constraint);
47 1
        }
48 1
    }
49
50
    /**
51
     * @param $value
52
     */
53 8
    private function assertConstraintInstance($value)
54
    {
55 8
        if (!$value instanceof Constraint) {
56 5
            throw new InvalidArgumentException(sprintf(
57 5
                'Expected a "%s" instance',
58
                Constraint::class
59 5
            ));
60
        }
61 3
    }
62
}
63