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

ProxyTrait::stub()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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