Completed
Pull Request — master (#37)
by Angelo
02:34
created

ProxyTrait::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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