Passed
Push — master ( 50117d...0ca86f )
by Pierre
10:55
created

DictionaryValidator::validate()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.0073

Importance

Changes 5
Bugs 1 Features 0
Metric Value
cc 5
eloc 15
c 5
b 1
f 0
nc 4
nop 2
dl 0
loc 23
ccs 14
cts 15
cp 0.9333
crap 5.0073
rs 9.4555
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Knp\DictionaryBundle\Validator\Constraints;
6
7
use Knp\DictionaryBundle\Dictionary\Collection;
8
use Symfony\Component\Validator\ConstraintValidator;
9
10
final class DictionaryValidator extends ConstraintValidator
11
{
12
    use DictionaryValidator\SymfonyCompatibilityTrait;
0 ignored issues
show
introduced by
The trait Knp\DictionaryBundle\Val...mfonyCompatibilityTrait requires some properties which are not provided by Knp\DictionaryBundle\Val...nts\DictionaryValidator: $name, $message
Loading history...
13
14
    /**
15
     * @var Collection
16
     */
17
    private $dictionaries;
18
19 5
    public function __construct(Collection $dictionaries)
20
    {
21 5
        $this->dictionaries = $dictionaries;
22 5
    }
23
24 4
    /**
25
     * @param mixed $var
26 4
     */
27 1
    private function varToString($var): string
28
    {
29
        if (null === $var) {
30 3
            return 'null';
31
        }
32
33
        if (\is_string($var)) {
34 3
            return '"'.$var.'"';
35 3
        }
36
37 3
        if (\is_bool($var)) {
38 2
            return $var ? 'true' : 'false';
39 2
        }
40
41 2
        if (\is_float($var)) {
42 2
            return 0.0 === $var
0 ignored issues
show
introduced by
The condition 0.0 === $var is always false.
Loading history...
43 2
                ? '0.0'
44 2
                : (string) $var
45 2
            ;
46
        }
47
48
        return (string) $var;
49
    }
50
}
51