Passed
Push — 4.3 ( 28cdbc...a1e8cd )
by David
14:50 queued 13:41
created

PathFinder::getPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
namespace Mouf\Database\TDBM\Utils\PathFinder;
3
4
use Mouf\Composer\ClassNameMapper;
5
6
class PathFinder implements PathFinderInterface
7
{
8
    /**
9
     * @var string
10
     */
11
    private $composerFile;
12
13
    /**
14
     * @var bool
15
     */
16
    private $useAutoloadDev;
17
18
    /**
19
     * @var ClassNameMapper
20
     */
21
    private $classNameMapper;
22
23
    public function __construct(string $composerFile = null, bool $useAutoloadDev = false)
24
    {
25
        $this->composerFile = $composerFile;
26
        $this->useAutoloadDev = $useAutoloadDev;
27
    }
28
29
    private function getClassNameMapper() : ClassNameMapper
30
    {
31
        if ($this->classNameMapper === null) {
32
            $this->classNameMapper = ClassNameMapper::createFromComposerFile($this->composerFile, null, $this->useAutoloadDev);
33
        }
34
        return $this->classNameMapper;
35
    }
36
37
    /**
38
     * Returns the path of a class file given the fully qualified class name.
39
     *
40
     * @param string $className
41
     * @return \SplFileInfo
42
     * @throws NoPathFoundException
43
     */
44
    public function getPath(string $className): \SplFileInfo
45
    {
46
        $paths = $this->getClassNameMapper()->getPossibleFileNames($className);
47
        if (empty($paths)) {
48
            throw NoPathFoundException::create($className);
49
        }
50
        return new \SplFileInfo($paths[0]);
51
    }
52
}
53