Completed
Push — master ( b72f37...0c7d03 )
by Alberto
15s
created

PhakeMockingStrategy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Plugin\Phake;
5
6
use Moka\Plugin\Phake\Matcher\FirstStubMatcher;
7
use Moka\Strategy\AbstractMockingStrategy;
8
use Moka\Stub\Stub;
9
use Phake;
10
use Phake_IMock as PhakeMock;
11
use Phake_Proxies_AnswerBinderProxy as AnswerBinderProxy;
12
13
/**
14
 * Class PhakeMockingStrategy
15
 * @package Moka\Plugin\Phake
16
 */
17
class PhakeMockingStrategy extends AbstractMockingStrategy
18
{
19
    /**
20
     * PhakeMockingStrategy constructor.
21
     */
22 2
    public function __construct()
23
    {
24 2
        $this->setMockType(PhakeMock::class);
25
    }
26
27
    /**
28
     * @param string $fqcn
29
     * @return PhakeMock
30
     */
31 21
    protected function doBuild(string $fqcn)
32
    {
33 21
        return Phake::mock($fqcn);
34
    }
35
36
    /**
37
     * @param PhakeMock $mock
38
     * @param Stub $stub
39
     * @return void
40
     */
41 21
    protected function doDecorate($mock, Stub $stub)
42
    {
43 21
        $methodName = $stub->getMethodName();
44 21
        $methodValue = $stub->getMethodValue();
45
46
        /** @var AnswerBinderProxy $partial */
47 21
        $partial = Phake::when($mock)->$methodName(new FirstStubMatcher($mock, $methodName));
48 21
        $methodValue instanceof \Throwable
49 21
            ? $partial->thenThrow($methodValue)
1 ignored issue
show
Compatibility introduced by
$methodValue of type object<Throwable> is not a sub-type of object<Exception>. It seems like you assume a concrete implementation of the interface Throwable to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
50 21
            : $partial->thenReturn($methodValue);
51
    }
52
53
    /**
54
     * @param PhakeMock $mock
55
     * @return PhakeMock
56
     */
57 10
    protected function doGet($mock)
58
    {
59 10
        return $mock;
60
    }
61
}
62