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

PhakeMockingStrategy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A doBuild() 0 4 1
A doDecorate() 0 11 2
A doGet() 0 4 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