ValidatorFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 5
cts 9
cp 0.5556
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 2
1
<?php declare(strict_types = 1);
2
3
namespace Simplex\Quickstart\Shared\Factory;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Doctrine\Common\Annotations\CachedReader;
7
use Doctrine\Common\Cache\FilesystemCache;
8
use Symfony\Component\Validator\Validation;
9
use Symfony\Component\Validator\Validator\ValidatorInterface;
10
11
final class ValidatorFactory
12
{
13
    private const VALIDATOR_CACHE_DIRECTORY = 'validator';
14
15 1
    public function create(bool $enableCache, \SplFileInfo $cacheDir): ValidatorInterface
16
    {
17 1
        $validationBuilder = Validation::createValidatorBuilder();
18
19 1
        if (!$enableCache) {
20
            return $validationBuilder
21 1
                ->enableAnnotationMapping()
22 1
                ->getValidator();
23
        }
24
25
        $cache = new FilesystemCache($cacheDir->getPathname() . DIRECTORY_SEPARATOR . self::VALIDATOR_CACHE_DIRECTORY);
26
27
        $annotationReader = new CachedReader(new AnnotationReader(), $cache);
28
29
        return $validationBuilder
30
            ->enableAnnotationMapping($annotationReader)
31
            ->getValidator();
32
    }
33
}
34