Passed
Push — master ( 897468...9581f6 )
by Lars
13:43
created

GetSoftDependencies::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace MagentoHackathon\Service;
5
6
use Magento\Framework\Component\ComponentRegistrar;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Component\ComponentRegistrar was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SimpleXMLElement;
8
9
class GetSoftDependencies
10
{
11
    /** @var ComponentRegistrar $registrar */
12
    private $componentRegistrar;
13
14
    public function __construct($componentRegistrar)
15
    {
16
        $this->componentRegistrar = $componentRegistrar;
17
    }
18
19
    /**
20
     * @param SimpleXMLElement $softDependenciesXml
21
     * @return array
22
     */
23
    public function execute(SimpleXMLElement $softDependenciesXml)
24
    {
25
26
        $path = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
27
28
        $softDependencies = [[]];
29
30
        if (isset($softDependenciesXml->module->sequence)) {
31
            return $softDependencies;
32
        }
33
34
        foreach ($softDependenciesXml->module->sequence->module as $module) {
35
            $moduleName = (string)$module->attributes()->name;
36
            if (\array_key_exists($moduleName, $path)) {
37
                $composerFilePath = preg_replace('/\/src$/', '', $path[$moduleName]);
0 ignored issues
show
Unused Code introduced by
The assignment to $composerFilePath is dead and can be removed.
Loading history...
38
            }
39
        }
40
41
        return array_merge(...$softDependencies);
42
    }
43
}
44