Checker::__invoke()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
rs 8.9197
cc 4
eloc 12
nc 6
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Marcosh\PhpTypeChecker;
6
7
use Marcosh\PhpTypeChecker\TypeHint\InputTypeHint;
8
use Marcosh\PhpTypeChecker\TypeHint\ReturnTypeHint;
9
use Roave\BetterReflection\Reflection\ReflectionMethod;
10
use Roave\BetterReflection\Reflector\ClassReflector;
11
use Roave\BetterReflection\Reflector\FunctionReflector;
12
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
13
14
final class Checker
15
{
16
    /**
17
     * @param string $path to be checked
18
     * @return \Iterator
19
     */
20
    public function __invoke(string $path): \Iterator
21
    {
22
        $directoriesSourceLocator = new DirectoriesSourceLocator([$path]);
23
24
        $classReflector = new ClassReflector($directoriesSourceLocator);
25
26
        foreach($classReflector->getAllClasses() as $class) {
27
            $methods = $class->getImmediateMethods();
28
29
            foreach ($methods as $method) {
30
                yield from ReturnTypeHint::method($method);
31
                yield from InputTypeHint::method($method);
32
            }
33
        }
34
35
        $functionReflector = new FunctionReflector($directoriesSourceLocator);
36
37
        foreach ($functionReflector->getAllFunctions() as $function) {
38
            yield from ReturnTypeHint::function($function);
39
            yield from InputTypeHint::function($function);
40
        }
41
    }
42
}
43