PreCommitExecuteFactory::fromArray()   D
last analyzed

Complexity

Conditions 10
Paths 512

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 10

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 4.1777
c 0
b 0
f 0
ccs 16
cts 16
cp 1
cc 10
nc 512
nop 1
crap 10

How to fix   Complexity   

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 PhpGitHooks\Module\Configuration\Domain\Execute;
6
use PhpGitHooks\Module\Configuration\Model\ExecuteInterface;
7
8
class PreCommitExecuteFactory
9
{
10
    /**
11
     * @param array $data
12
     *
13
     * @return ExecuteInterface
14
     */
15 1
    public static function fromArray(array $data)
16
    {
17
        $tools = [
18 1
            isset($data['composer']) ? ComposerFactory::fromArray($data['composer']) : ComposerFactory::setUndefined(),
19 1
            isset($data['jsonlint']) ? JsonLintFactory::fromArray($data['jsonlint']) : JsonLintFactory::setUndefined(),
20 1
            isset($data['phplint']) ? PhpLintFactory::fromArray($data['phplint']) : PhpLintFactory::setUndefined(),
21 1
            isset($data['phpmd']) ? PhpMdFactory::fromArray($data['phpmd']) : PhpMdFactory::setUndefined(),
22 1
            isset($data['phpcs']) ? PhpCsFactory::fromArray($data['phpcs']) : PhpCsFactory::setUndefined(),
23 1
            isset($data['php-cs-fixer']) ? PhpCsFixerFactory::fromArray($data['php-cs-fixer']) :
24 1
                PhpCsFixerFactory::setUndefined(),
25 1
            isset($data['phpunit']) ? PhpUnitFactory::fromArray($data['phpunit']) : PhpUnitFactory::setUndefined(),
26 1
            isset($data['phpunit']['strict-coverage']) ? PhpUnitStrictCoverageFactory::fromArray(
27 1
                $data['phpunit']['strict-coverage']
28 1
            ) : PhpUnitStrictCoverageFactory::setUndefined(),
29 1
            isset($data['phpunit']['guard-coverage']) ? PhpUnitGuardCoverageFactory::build(
30 1
                $data['phpunit']['guard-coverage']
31 1
            ) : PhpUnitGuardCoverageFactory::setUndefined(),
32
        ];
33
34 1
        return new Execute($tools);
35
    }
36
37
    /**
38
     * @return Execute
39
     */
40 3
    public static function setUndefined()
41
    {
42
        $tools = [
43 3
            ComposerFactory::setUndefined(),
44 3
            JsonLintFactory::setUndefined(),
45 3
            PhpLintFactory::setUndefined(),
46 3
            PhpMdFactory::setUndefined(),
47 3
            PhpCsFactory::setUndefined(),
48 3
            PhpCsFixerFactory::setUndefined(),
49 3
            PhpUnitFactory::setUndefined(),
50 3
            PhpUnitStrictCoverageFactory::setUndefined(),
51 3
            PhpUnitGuardCoverageFactory::setUndefined(),
52
        ];
53
54 3
        return new Execute($tools);
55
    }
56
}
57