Completed
Push — master ( 0e228a...b2cc89 )
by Tobias
54:46 queued 19:48
created

AnnotationValidator::validateClasses()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
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
 *
12
 *
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15
class AnnotationValidator
16
{
17
    private $reader;
18
19
    public function __construct(Reader $reader)
20
    {
21
        $this->reader = $reader;
22
    }
23
24
    /**
25
     * @returns AnnotationException[]
26
     */
27
    public function validateClasses(array $classes): array
28
    {
29
        $exceptions = [];
30
        foreach ($classes as $class) {
31
            try {
32
                $this->validateClass($class);
33
            } catch (AnnotationException $e) {
34
                $exceptions[] = $e;
35
            }
36
        }
37
38
        return $exceptions;
39
    }
40
41
    private function validateClass($class)
42
    {
43
        $reflectionClass = new \ReflectionClass($class);
44
        $this->reader->getClassAnnotations($reflectionClass);
45
46
        foreach ($reflectionClass->getMethods() as $reflectionMethod) {
47
            $this->reader->getMethodAnnotations($reflectionMethod);
48
        }
49
50
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
51
            $this->reader->getPropertyAnnotations($reflectionProperty);
52
        }
53
    }
54
}
55