Completed
Pull Request — master (#37)
by Angelo
03:16 queued 01:16
created

ProxyTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 57
ccs 7
cts 12
cp 0.5833
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __call() 0 6 2
A _moka_setObject() 0 4 1
A _moka_setMockingStrategy() 0 4 1
A stub() 0 6 1
A serve() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Generator;
5
6
use Moka\Exception\InvalidArgumentException;
7
use Moka\Exception\MockNotCreatedException;
8
use Moka\Exception\MockNotServedException;
9
use Moka\Proxy\ProxyInterface;
10
use Moka\Strategy\MockingStrategyInterface;
11
12
trait ProxyTrait
13
{
14
    private $object;
15
16
    /**
17
     * @var MockingStrategyInterface
18
     */
19
    private $mockingStrategy;
20
21
    public function __construct()
22
    {
23
    }
24
25 1
    public function __call($name, array $arguments)
26
    {
27 1
        if ($this->mockingStrategy instanceof MockingStrategyInterface) {
28 1
            return $this->mockingStrategy->call($this->object, $name, $arguments);
29
        }
30
    }
31
32
    /**
33
     * @param mixed $object
34
     */
35 8
    public function _moka_setObject($object)
36
    {
37 8
        $this->object = $object;
38
    }
39
40 8
    public function _moka_setMockingStrategy(MockingStrategyInterface $mockingStrategy)
41
    {
42 8
        $this->mockingStrategy = $mockingStrategy;
43
    }
44
45
    /**
46
     * @param array $methodsWithValues
47
     * @return ProxyInterface
48
     *
49
     * @throws InvalidArgumentException
50
     * @throws MockNotCreatedException
51
     */
52
    public function stub(array $methodsWithValues): ProxyInterface
53
    {
54
        $this->mockingStrategy->decorate($this->object, $methodsWithValues);
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return object
61
     *
62
     * @throws MockNotServedException
63
     */
64
    public function serve()
65
    {
66
        return $this->object;
67
    }
68
}
69