1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Configuration\Service; |
4
|
|
|
|
5
|
|
|
use Composer\IO\IOInterface; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Domain\Execute; |
7
|
|
|
use PhpGitHooks\Module\Configuration\Domain\PrePush; |
8
|
|
|
use PhpGitHooks\Module\Configuration\Model\ExecuteInterface; |
9
|
|
|
|
10
|
|
|
class PrePushProcessor |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var IOInterface |
14
|
|
|
*/ |
15
|
|
|
private $input; |
16
|
|
|
/** |
17
|
|
|
* @var PhpUnitGuardCoverageConfigurator |
18
|
|
|
*/ |
19
|
|
|
private $phpUnitGuardCoverageConfigurator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* PrePushProcessor constructor. |
23
|
|
|
* |
24
|
|
|
* @param PhpUnitGuardCoverageConfigurator $phpUnitGuardCoverageConfigurator |
25
|
|
|
*/ |
26
|
2 |
|
public function __construct(PhpUnitGuardCoverageConfigurator $phpUnitGuardCoverageConfigurator) |
27
|
|
|
{ |
28
|
2 |
|
$this->phpUnitGuardCoverageConfigurator = $phpUnitGuardCoverageConfigurator; |
29
|
2 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param PrePush $prePushData |
33
|
|
|
* @param IOInterface $input |
34
|
|
|
* |
35
|
|
|
* @return PrePush |
36
|
|
|
*/ |
37
|
2 |
View Code Duplication |
public function process(PrePush $prePushData, IOInterface $input) |
|
|
|
|
38
|
|
|
{ |
39
|
2 |
|
$this->input = $input; |
40
|
2 |
|
if (true === $prePushData->isUndefined()) { |
41
|
1 |
|
$prePushData = PrePushConfigurator::configure($this->input, $prePushData); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
2 |
|
if (true === $prePushData->isEnabled()) { |
45
|
2 |
|
$prePushData = $prePushData->setExecute($this->configTools($prePushData->getExecute())); |
46
|
2 |
|
} |
47
|
|
|
|
48
|
2 |
|
return $prePushData; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param ExecuteInterface $execute |
53
|
|
|
* |
54
|
|
|
* @return Execute |
55
|
|
|
*/ |
56
|
2 |
|
protected function configTools(ExecuteInterface $execute) |
57
|
|
|
{ |
58
|
2 |
|
$tools = $execute->execute(); |
59
|
|
|
|
60
|
2 |
|
$tools[0] = PhpUnitConfigurator::configure($this->input, $tools[0]); |
|
|
|
|
61
|
2 |
|
$tools[1] = PhpUnitStrictCoverageConfigurator::configure($this->input, $tools[1]); |
62
|
2 |
|
$tools[2] = $this->phpUnitGuardCoverageConfigurator->configure($this->input, $tools[2]); |
63
|
|
|
|
64
|
2 |
|
return new Execute($tools); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.