AnnotationValidator::validateClasses()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Happyr\AnnotationWarmer\Service;
6
7
use Doctrine\Common\Annotations\AnnotationException;
8
use Doctrine\Common\Annotations\Reader;
9
10
/**
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
class AnnotationValidator
14
{
15
    private $reader;
16
17 1
    public function __construct(Reader $reader)
18
    {
19 1
        $this->reader = $reader;
20 1
    }
21
22
    /**
23
     * @returns AnnotationException[]
24
     */
25 1
    public function validateClasses(array $classes): array
26
    {
27 1
        $exceptions = [];
28 1
        foreach ($classes as $class) {
29
            try {
30 1
                $this->validateClass($class);
31 1
            } catch (AnnotationException $e) {
32 1
                $exceptions[] = $e;
33
            }
34
        }
35
36 1
        return $exceptions;
37
    }
38
39 1
    private function validateClass($class)
40
    {
41 1
        $reflectionClass = new \ReflectionClass($class);
42 1
        $this->reader->getClassAnnotations($reflectionClass);
43
44 1
        foreach ($reflectionClass->getMethods() as $reflectionMethod) {
45
            $this->reader->getMethodAnnotations($reflectionMethod);
46
        }
47
48 1
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
49 1
            $this->reader->getPropertyAnnotations($reflectionProperty);
50
        }
51 1
    }
52
}
53