Passed
Push — 1.x ( 86c739...7c9ad4 )
by Akihito
02:27
created

TestDoubleModule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B configure() 0 30 3
1
<?php
2
/**
3
 * This file is part of the Ray.TestDouble package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\TestDouble;
8
9
use Ray\Di\AbstractModule;
10
use Ray\Di\Scope;
11
use Ray\TestDouble\Annotation\Fakeable;
12
13
class TestDoubleModule extends AbstractModule
14
{
15
    /**
16
     * @var array
17
     */
18
    private $fakeables;
19
20
    /**
21
     * @var array
22
     */
23
    private $spies;
24
25
    public function __construct(array $fakeables = [], array $spies = [], AbstractModule $module = null)
26
    {
27
        $this->fakeables = $fakeables;
28
        $this->spies = $spies;
29
        parent::__construct($module);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function configure()
36
    {
37
        $this->bind(Spy::class)->in(Scope::SINGLETON);
38
        $this->bindInterceptor(
39
            $this->matcher->annotatedWith(\Ray\TestDouble\Annotation\Spy::class),
40
            $this->matcher->any(),
41
            [SpyInterceptor::class]
42
        );
43
        $this->bindInterceptor(
44
            $this->matcher->any(),
45
            $this->matcher->annotatedWith(\Ray\TestDouble\Annotation\Spy::class),
46
            [SpyInterceptor::class]
47
        );
48
        foreach ($this->spies as $spy) {
49
            $this->bindInterceptor(
50
                $this->matcher->subclassesOf($spy),
51
                $this->matcher->any(),
52
                [SpyInterceptor::class]
53
            );
54
        }
55
        $this->bindInterceptor(
56
            $this->matcher->annotatedWith(Fakeable::class),
57
            $this->matcher->any(),
58
            [TestDoubleInterceptor::class]
59
        );
60
        foreach ($this->fakeables as $fakeable) {
61
            $this->bindInterceptor(
62
                $this->matcher->subclassesOf($fakeable),
63
                $this->matcher->any(),
64
                [TestDoubleInterceptor::class]
65
            );
66
        }
67
    }
68
}
69