Completed
Push — master ( ac38d0...343642 )
by Marco
12s
created

Autoloader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Autoloader;
6
7
use ProxyManager\FileLocator\FileLocatorInterface;
8
use ProxyManager\Inflector\ClassNameInflectorInterface;
9
10
/**
11
 * {@inheritDoc}
12
 *
13
 * @author Marco Pivetta <[email protected]>
14
 * @license MIT
15
 */
16
class Autoloader implements AutoloaderInterface
17
{
18
    /**
19
     * @var \ProxyManager\FileLocator\FileLocatorInterface
20
     */
21
    protected $fileLocator;
22
23
    /**
24
     * @var \ProxyManager\Inflector\ClassNameInflectorInterface
25
     */
26
    protected $classNameInflector;
27
28
    /**
29
     * @param \ProxyManager\FileLocator\FileLocatorInterface      $fileLocator
30
     * @param \ProxyManager\Inflector\ClassNameInflectorInterface $classNameInflector
31
     */
32 4
    public function __construct(FileLocatorInterface $fileLocator, ClassNameInflectorInterface $classNameInflector)
33
    {
34 4
        $this->fileLocator        = $fileLocator;
35 4
        $this->classNameInflector = $classNameInflector;
36 4
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 4
    public function __invoke(string $className) : bool
42
    {
43 4
        if (class_exists($className, false) || ! $this->classNameInflector->isProxyClassName($className)) {
44 2
            return false;
45
        }
46
47 2
        $file = $this->fileLocator->getProxyFileName($className);
48
49 2
        if (! file_exists($file)) {
50 1
            return false;
51
        }
52
53
        /* @noinspection PhpIncludeInspection */
54
        /* @noinspection UsingInclusionOnceReturnValueInspection */
55 1
        return (bool) require_once $file;
56
    }
57
}
58