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

Autoloader::__invoke()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 1
crap 4
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