1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Amock\MockMethod; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
class Resolver |
8
|
|
|
{ |
9
|
|
|
private $testCase; |
10
|
|
|
|
11
|
|
|
private $initialStub; |
12
|
|
|
|
13
|
|
|
private $methodName; |
14
|
|
|
|
15
|
|
|
private $methodMockConfig; |
16
|
|
|
|
17
|
19 |
View Code Duplication |
public function __construct(TestCase $testCase, $initialStub, string $methodName, $methodMockConfig) |
|
|
|
|
18
|
|
|
{ |
19
|
19 |
|
$this->testCase = $testCase; |
20
|
19 |
|
$this->initialStub = $initialStub; |
21
|
19 |
|
$this->methodName = $methodName; |
22
|
19 |
|
$this->methodMockConfig = $methodMockConfig; |
23
|
19 |
|
} |
24
|
|
|
|
25
|
19 |
|
public function resolveAndModifyStub() |
26
|
|
|
{ |
27
|
19 |
|
$stringReturn = new StringReturn($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
28
|
19 |
|
$integerReturn = new IntegerReturn($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
29
|
19 |
|
$arrayReturn = new ArrayReturn($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
30
|
19 |
|
$nullReturn = new NullReturn($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
31
|
19 |
|
$booleanReturn = new BooleanReturn($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
32
|
19 |
|
$selfReturn = new SelfReturn($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
33
|
19 |
|
$consecutiveCallsReturn = new ConsecutiveCallsReturn($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
34
|
19 |
|
$exceptionThrow = new ExceptionThrow($this->testCase, $this->initialStub, $this->methodName, $this->methodMockConfig); |
35
|
|
|
|
36
|
19 |
|
$stringReturn->setSuccessor($arrayReturn); |
37
|
19 |
|
$arrayReturn->setSuccessor($nullReturn); |
38
|
19 |
|
$nullReturn->setSuccessor($selfReturn); |
39
|
19 |
|
$selfReturn->setSuccessor($booleanReturn); |
40
|
19 |
|
$booleanReturn->setSuccessor($integerReturn); |
41
|
19 |
|
$integerReturn->setSuccessor($consecutiveCallsReturn); |
42
|
19 |
|
$consecutiveCallsReturn->setSuccessor($exceptionThrow); |
43
|
|
|
|
44
|
19 |
|
return $stringReturn->process(); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
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.