Test Failed
Pull Request — master (#17)
by Yo
02:38
created

ConfigurationFileUpdater::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
ccs 5
cts 5
cp 1
cc 1
eloc 9
nc 1
nop 4
crap 1
1
<?php
2
namespace Yoanm\ComposerConfigManager\Application\Updater;
3
4
use Yoanm\ComposerConfigManager\Domain\Model\Configuration;
5
use Yoanm\ComposerConfigManager\Domain\Model\ConfigurationFile;
6
7
class ConfigurationFileUpdater
8
{
9
    /** @var PlainValueUpdater */
10
    private $plainValueUpdater;
11
    /** @var KeywordListUpdater */
12
    private $keywordListUpdater;
13
    /** @var ListUpdater */
14
    private $listUpdater;
15
    /** @var AuthorListUpdater */
16
    private $authorListUpdater;
17 1
18
    public function __construct(
19
        PlainValueUpdater $plainValueUpdater,
20
        KeywordListUpdater $keywordListUpdater,
21
        ListUpdater $listUpdater,
22
        AuthorListUpdater $authorListUpdater
23 1
    ) {
24 1
        $this->plainValueUpdater = $plainValueUpdater;
25 1
        $this->keywordListUpdater = $keywordListUpdater;
26 1
        $this->listUpdater = $listUpdater;
27 1
        $this->authorListUpdater = $authorListUpdater;
28
    }
29
30
    /**
31
     * @param ConfigurationFile[] $configurationList
32
     *
33
     * @return ConfigurationFile
34 1
     */
35
    public function update(array $configurationList)
36 1
    {
37
        $newConfigurationFile = array_pop($configurationList);
38 1
39 1
        while (count($configurationList) > 0) {
40 1
            $baseConfigurationFile = array_pop($configurationList);
41 1
            $newConfigurationFile = $this->merge($baseConfigurationFile, $newConfigurationFile);
1 ignored issue
show
Bug introduced by
It seems like $newConfigurationFile can be null; however, merge() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
42
        }
43 1
44
        return $newConfigurationFile;
45
    }
46
47
48
    /**
49
     * @param ConfigurationFile $baseConfigurationFile
50
     * @param ConfigurationFile $newConfigurationFile
51
     *
52
     * @return ConfigurationFile
53 1
     */
54
    public function merge(ConfigurationFile $baseConfigurationFile, ConfigurationFile $newConfigurationFile)
55 1
    {
56 1
        return new ConfigurationFile(
57 1
            $this->mergeConfiguration(
58 1
                $baseConfigurationFile->getConfiguration(),
59 1
                $newConfigurationFile->getConfiguration()
60 1
            ),
61 1
            $this->mergeConfigurationKeys(
0 ignored issues
show
Bug introduced by
The method mergeConfigurationKeys() does not exist on Yoanm\ComposerConfigMana...onfigurationFileUpdater. Did you maybe mean mergeConfiguration()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
62 1
                $baseConfigurationFile->getKeyList(),
63 1
                $newConfigurationFile->getKeyList()
64 1
            )
65 1
        );
66 1
    }
67 1
68 1
    protected function mergeConfiguration(Configuration $baseConfiguration, Configuration $newConfiguration)
69 1
    {
70 1
        return new Configuration(
71 1
            $this->plainValueUpdater->update(
72 1
                $newConfiguration->getPackageName(),
73 1
                $baseConfiguration->getPackageName()
74 1
            ),
75 1
            $this->plainValueUpdater->update(
76 1
                $newConfiguration->getType(),
77 1
                $baseConfiguration->getType()
78 1
            ),
79 1
            $this->plainValueUpdater->update(
80 1
                $newConfiguration->getLicense(),
81 1
                $baseConfiguration->getLicense()
82 1
            ),
83 1
            $this->plainValueUpdater->update(
84 1
                $newConfiguration->getPackageVersion(),
85 1
                $baseConfiguration->getPackageVersion()
86 1
            ),
87 1
            $this->plainValueUpdater->update(
88 1
                $newConfiguration->getDescription(),
89 1
                $baseConfiguration->getDescription()
90 1
            ),
91 1
            $this->keywordListUpdater->update(
92 1
                $newConfiguration->getKeywordList(),
93 1
                $baseConfiguration->getKeywordList()
94 1
            ),
95 1
            $this->authorListUpdater->update($newConfiguration->getAuthorList(), $baseConfiguration->getAuthorList()),
96 1
            $this->listUpdater->update(
97 1
                $newConfiguration->getProvidedPackageList(),
98 1
                $baseConfiguration->getProvidedPackageList()
99 1
            ),
100 1
            $this->listUpdater->update(
101 1
                $newConfiguration->getSuggestedPackageList(),
102 1
                $baseConfiguration->getSuggestedPackageList()
103 1
            ),
104 1
            $this->listUpdater->update($newConfiguration->getSupportList(), $baseConfiguration->getSupportList()),
105
            $this->listUpdater->update($newConfiguration->getAutoloadList(), $baseConfiguration->getAutoloadList()),
106
            $this->listUpdater->update(
107
                $newConfiguration->getAutoloadDevList(),
108
                $baseConfiguration->getAutoloadDevList()
109
            ),
110
            $this->listUpdater->update(
111
                $newConfiguration->getRequiredPackageList(),
112
                $baseConfiguration->getRequiredPackageList()
113
            ),
114
            $this->listUpdater->update(
115
                $newConfiguration->getRequiredDevPackageList(),
116
                $baseConfiguration->getRequiredDevPackageList()
117
            ),
118
            $this->listUpdater->update($newConfiguration->getScriptList(), $baseConfiguration->getScriptList())
119
        );
120
    }
121
122
    protected function mergeKeyList(array $baseKeyList, array $newKeyList)
0 ignored issues
show
Unused Code introduced by
The parameter $baseKeyList is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $newKeyList is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
123
    {
124
125
    }
126
}
127