Completed
Branch module_structure (3116d9)
by Pablo
02:56
created

getConfigurationDataResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 40
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 52
rs 9.4929
ccs 40
cts 40
cp 1
cc 1
eloc 40
nc 1
nop 1
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpGitHooks\Module\Configuration\Service;
4
5
use CommandBus\QueryBus\QueryInterface;
6
use PhpGitHooks\Module\Configuration\Contract\Response\ConfigurationDataResponse;
7
use PhpGitHooks\Module\Configuration\Domain\CommitMsg;
8
use PhpGitHooks\Module\Configuration\Domain\Config;
9
use PhpGitHooks\Module\Configuration\Domain\PhpCs;
10
use PhpGitHooks\Module\Configuration\Domain\PhpCsFixer;
11
use PhpGitHooks\Module\Configuration\Domain\PhpUnit;
12
use PhpGitHooks\Module\Configuration\Domain\PreCommit;
13
use PhpGitHooks\Module\Configuration\Domain\PrePush;
14
use PhpGitHooks\Module\Configuration\Model\ConfigurationFileReaderInterface;
15
16
class ConfigurationDataFinder implements QueryInterface
17
{
18
    /**
19
     * @var ConfigurationFileReaderInterface
20
     */
21
    private $configurationFileReader;
22
23
    /**
24
     * ConfigurationDataFinder constructor.
25
     *
26
     * @param ConfigurationFileReaderInterface $configurationFileReader
27
     */
28 1
    public function __construct(ConfigurationFileReaderInterface $configurationFileReader)
29
    {
30 1
        $this->configurationFileReader = $configurationFileReader;
31 1
    }
32
33
    /**
34
     * @return ConfigurationDataResponse
35
     */
36 1
    public function find()
37
    {
38 1
        $data = $this->configurationFileReader->getData();
39
40 1
        return $this->getConfigurationDataResponse($data);
41
    }
42
43 1
    private function getConfigurationDataResponse(Config $data)
44
    {
45
        /** @var PreCommit $preCommit */
46 1
        $preCommit = $data->getPreCommit();
47
        /** @var CommitMsg $commitMsg */
48 1
        $commitMsg = $data->getCommitMsg();
49 1
        $tools = $preCommit->getExecute()->execute();
50
        /** @var PrePush $prePush */
51 1
        $prePush = $data->getPrePush();
52 1
        $prePushTools = $prePush->getExecute()->execute();
53
54 1
        $composer = $tools[0];
55 1
        $jsonLint = $tools[1];
56 1
        $phpLint = $tools[2];
57 1
        $phpMd = $tools[3];
58
        /** @var PhpCs $phpCs */
59 1
        $phpCs = $tools[4];
60
        /** @var PhpCsFixer $phpCsFixer */
61 1
        $phpCsFixer = $tools[5];
62
        /** @var PhpUnit $phpUnit */
63 1
        $phpUnit = $tools[6];
64
        /** @var PhpUnit $prePushPhpUnit */
65 1
        $prePushPhpUnit = $prePushTools[0];
66
67 1
        return new ConfigurationDataResponse(
68 1
            $preCommit->isEnabled(),
69 1
            $preCommit->getMessages()->getRightMessage()->value(),
70 1
            $preCommit->getMessages()->getErrorMessage()->value(),
71 1
            $composer->isEnabled(),
72 1
            $jsonLint->isEnabled(),
73 1
            $phpLint->isEnabled(),
74 1
            $phpMd->isEnabled(),
75 1
            $phpCs->isEnabled(),
76 1
            $phpCs->getStandard()->value(),
77 1
            $phpCsFixer->isEnabled(),
78 1
            $phpCsFixer->getLevels()->getPsr0()->value(),
79 1
            $phpCsFixer->getLevels()->getPsr1()->value(),
80 1
            $phpCsFixer->getLevels()->getPsr2()->value(),
81 1
            $phpCsFixer->getLevels()->getSymfony()->value(),
82 1
            $phpUnit->isEnabled(),
83 1
            $phpUnit->getRandomMode()->value(),
84 1
            $phpUnit->getOptions()->value(),
85 1
            $commitMsg->isEnabled(),
86 1
            $commitMsg->getRegularExpression()->value(),
87 1
            $prePush->isEnabled(),
88 1
            $prePushPhpUnit->isEnabled(),
89 1
            $prePushPhpUnit->getRandomMode()->value(),
90 1
            $prePushPhpUnit->getOptions()->value(),
91 1
            $prePush->getMessages()->getRightMessage()->value(),
92 1
            $prePush->getMessages()->getErrorMessage()->value()
93
        );
94
    }
95
}
96