ProxyAutoloader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 38
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 4 1
A unregister() 0 4 1
A getAutoloaderClosure() 0 13 3
1
<?php
2
3
namespace PHPRealCoverage\Proxy;
4
5
class ProxyAutoloader
6
{
7
    /**
8
     * @var ProxyFactory
9
     */
10
    private $factory = null;
11
12
    private $autoloaderClosue = null;
13
14
    public function __construct(ProxyFactory $factory)
15
    {
16
        $this->factory = $factory;
17
    }
18
19
    public function register()
20
    {
21
        spl_autoload_register($this->getAutoloaderClosure(), true, true);
22
    }
23
24
    public function unregister()
25
    {
26
        spl_autoload_unregister($this->autoloaderClosue);
27
    }
28
29
    public function getAutoloaderClosure()
30
    {
31
        if (is_null($this->autoloaderClosue)) {
32
            $factory = $this->factory;
33
            $this->autoloaderClosue = function ($class) use ($factory) {
34
                if (!$factory->supports($class)) {
35
                    return;
36
                }
37
                $factory->getProxyForName($class);
38
            };
39
        }
40
        return $this->autoloaderClosue;
41
    }
42
}
43