Reflection::locate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Kambo\Testing\ClassOpener\ClassManipulation\Locator;
4
5
use BetterReflection\Reflector\Reflector;
6
7
use Exception;
8
use Kambo\Testing\ClassOpener\ClassManipulation\Exception\NotFoundException;
9
use Kambo\Testing\ClassOpener\ClassManipulation\Locator;
10
11
/**
12
 * Locate a class filename with path without actual loading.
13
 *
14
 * @author  Bohuslav Simek <[email protected]>
15
 * @license MIT
16
 */
17
class Reflection implements Locator
18
{
19
    private $reflector;
20
21
    /**
22
     * Constructor
23
     *
24
     * @param string $reflector Roave BetterReflection reflector
25
     */
26 4
    public function __construct(Reflector $reflector)
27
    {
28 4
        $this->reflector = $reflector;
29 4
    }
30
31
    /**
32
     * Get the file path to the class
33
     *
34
     * @param string $className Name of the class
35
     *
36
     * @return string File path to the file
37
     */
38 4
    public function locate(string $className) : string
39
    {
40
        try {
41 4
            $reflectionClass = $this->reflector->reflect($className);
42 1
        } catch (Exception $e) {
43 1
            throw new NotFoundException("Unable to locate class {$className}");
44
        }
45
46 3
        return realpath($reflectionClass->getFileName());
47
    }
48
}
49