BooleanConstraintValidator::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
ccs 5
cts 5
cp 1
crap 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Schema\Validators\Constraints;
11
12
use Symfony\Component\Validator\Constraints\Choice;
13
use Symfony\Component\Validator\Constraints\NotNull;
14
use Symfony\Component\Validator\ConstraintViolationListInterface;
15
use Symfony\Component\Validator\Validation;
16
17
/**
18
 * @Annotation
19
 */
20
class BooleanConstraintValidator
21
{
22
    /**
23
     * @param bool $bool
24
     */
25 175
    public function validate($bool): ConstraintViolationListInterface
26
    {
27 175
        $validator = Validation::createValidator();
28
29 175
        return $validator->validate($bool, [
30 175
            new NotNull(),
31 175
            new Choice([true, false, 'true', 'false']),
32
        ]);
33
    }
34
}
35