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

PHPUnitMockingStrategy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 17.86 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 10
loc 56
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A doBuild() 0 10 1
A doDecorate() 10 10 2
A doGet() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Plugin\PHPUnit;
5
6
use Moka\Strategy\AbstractMockingStrategy;
7
use Moka\Stub\Stub;
8
use PHPUnit_Framework_MockObject_Generator as MockGenerator;
9
use PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount as AnyInvokedCountMatcher;
10
use PHPUnit_Framework_MockObject_MockObject as MockObject;
11
12
/**
13
 * Class PHPUnitMockingStrategy
14
 * @package Moka\Strategy
15
 */
16
class PHPUnitMockingStrategy extends AbstractMockingStrategy
17
{
18
    /**
19
     * @var MockGenerator
20
     */
21
    private $generator;
22
23
    /**
24
     * PHPUnitMockingStrategy constructor.
25
     */
26 4
    public function __construct()
27
    {
28 4
        $this->generator = new MockGenerator();
29 4
        $this->setMockType(MockObject::class);
30
    }
31
32
    /**
33
     * @param string $fqcn
34
     * @return MockObject
35
     */
36 21
    protected function doBuild(string $fqcn)
37
    {
38 21
        return $this->generator->getMock(
39 21
            $fqcn,
40 21
            $methods = [],
41 21
            $arguments = [],
42 21
            $mockClassName = '',
43 21
            $callOriginalConstructor = false
44
        );
45
    }
46
47
    /**
48
     * @param MockObject $mock
49
     * @param Stub $stub
50
     * @return void
51
     */
52 21 View Code Duplication
    protected function doDecorate($mock, Stub $stub)
1 ignored issue
show
Duplication introduced by Alberto Villa
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54 21
        $methodName = $stub->getMethodName();
55 21
        $methodValue = $stub->getMethodValue();
56
57 21
        $partial = $mock->expects(new AnyInvokedCountMatcher())->method($methodName);
58 21
        $methodValue instanceof \Throwable
59 21
            ? $partial->willThrowException($methodValue)
60 21
            : $partial->willReturn($methodValue);
61
    }
62
63
    /**
64
     * @param MockObject $mock
65
     * @return MockObject
66
     */
67 10
    protected function doGet($mock)
68
    {
69 10
        return $mock;
70
    }
71
}
72