Reflection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 32
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A locate() 0 10 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