Passed
Pull Request — master (#160)
by Pierre
02:39 queued 34s
created

DictionaryValidator::varToString()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7.0283

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 7
eloc 11
c 1
b 1
f 0
nc 7
nop 1
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
crap 7.0283
rs 8.8333
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\Form\Exception\UnexpectedTypeException;
9
use Symfony\Component\Validator\Constraint;
10
use Symfony\Component\Validator\ConstraintValidator;
11
12
final class DictionaryValidator extends ConstraintValidator
13
{
14
    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...
15
16
    /**
17
     * @var Collection
18
     */
19 5
    private $dictionaries;
20
21 5
    public function __construct(Collection $dictionaries)
22 5
    {
23
        $this->dictionaries = $dictionaries;
24 4
    }
25
26 4
    /**
27 1
     * @param mixed $var
28
     */
29
    private function varToString($var): string
30 3
    {
31
        if (null === $var) {
32
            return 'null';
33
        }
34 3
35 3
        if (\is_string($var)) {
36
            return '"'.$var.'"';
37 3
        }
38 2
39 2
        if (\is_bool($var)) {
40
            return $var ? 'true' : 'false';
41 2
        }
42 2
43 2
        if (\is_float($var)) {
44 2
            return 0.0 === $var
0 ignored issues
show
introduced by
The condition 0.0 === $var is always false.
Loading history...
45 2
                ? '0.0'
46
                : (string) $var
47
            ;
48
        }
49
50
        return (string) $var;
51
    }
52
}
53