PhpExtensions::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Firegento\DevDashboard\ViewModel\Widget;
4
5
use Magento\Framework\View\Element\Block\ArgumentInterface;
6
use Magento\Framework\Composer\ComposerInformation;
7
use Magento\Setup\Model\PhpInformation;
0 ignored issues
show
Bug introduced by
The type Magento\Setup\Model\PhpInformation 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...
8
9
class PhpExtensions implements ArgumentInterface
10
{
11
    private $composerInformation;
12
13
    private $phpInformation;
14
15
    public function __construct(
16
        ComposerInformation $composerInformation,
17
        PhpInformation $phpInformation
18
    ) {
19
        $this->composerInformation = $composerInformation;
20
        $this->phpInformation = $phpInformation;
21
    }
22
23
    public function getPhpExtensions()
24
    {
25
        $required = $this->composerInformation->getRequiredExtensions();
26
        $current = $this->phpInformation->getCurrent();
27
        return array_values($required + $current);
28
    }
29
30
    public function getPhpExtensionStatus($extension)
31
    {
32
        $required = $this->composerInformation->getRequiredExtensions();
33
        $current = $this->phpInformation->getCurrent();
34
35
        $requiredInstalledPhpExtensions = array_intersect($required, $current);
36
        $requiredMissingPhpExtensions = array_diff($required, $current);
37
38
        if (in_array($extension, $requiredInstalledPhpExtensions)) {
39
            return 'required-installed';
40
        }
41
        if (in_array($extension, $requiredMissingPhpExtensions)) {
42
            return 'required-missing';
43
        }
44
        return 'optional-installed';
45
    }
46
}
47