Completed
Pull Request — master (#109)
by Jan Philipp
04:46
created

ProcessEnvironment   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 66
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getAllValues() 0 8 1
A getTemplates() 0 4 1
A createProcess() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Psh\ScriptRuntime\Execution;
4
5
use Shopware\Psh\Config\Template;
6
use Shopware\Psh\Config\ValueProvider;
7
use Symfony\Component\Process\Process;
8
use Webmozart\Assert\Assert;
9
use function array_merge;
10
11
/**
12
 * Create representation of the current environment variables and constants
13
 */
14
class ProcessEnvironment
15
{
16
    /**
17
     * @var ValueProvider[]
18
     */
19
    private $constants;
20
21
    /**
22
     * @var ValueProvider[]
23
     */
24
    private $variables;
25
26
    /**
27
     * @var Template[]
28
     */
29
    private $templates;
30
31
    /**
32
     * @var ValueProvider[]
33
     */
34
    private $dotenvVariables;
35
36
    /**
37
     * @param ValueProvider[] $constants
38
     * @param ValueProvider[] $variables
39
     * @param Template[] $templates
40
     * @param ValueProvider[] $dotenvVars
41
     */
42
    public function __construct(array $constants, array $variables, array $templates, array $dotenvVars)
43
    {
44
        Assert::allIsInstanceOf($constants, ValueProvider::class);
0 ignored issues
show
Bug introduced by
The method allIsInstanceOf() does not exist on Webmozart\Assert\Assert. Did you maybe mean isInstanceOf()?

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...
45
        Assert::allIsInstanceOf($variables, ValueProvider::class);
0 ignored issues
show
Bug introduced by
The method allIsInstanceOf() does not exist on Webmozart\Assert\Assert. Did you maybe mean isInstanceOf()?

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...
46
        Assert::allIsInstanceOf($dotenvVars, ValueProvider::class);
0 ignored issues
show
Bug introduced by
The method allIsInstanceOf() does not exist on Webmozart\Assert\Assert. Did you maybe mean isInstanceOf()?

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...
47
        Assert::allIsInstanceOf($templates, Template::class);
0 ignored issues
show
Bug introduced by
The method allIsInstanceOf() does not exist on Webmozart\Assert\Assert. Did you maybe mean isInstanceOf()?

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...
48
49
        $this->constants = $constants;
50
        $this->variables = $variables;
51
        $this->templates = $templates;
52
        $this->dotenvVariables = $dotenvVars;
53
    }
54
55
    /**
56
     * @return ValueProvider[]
57
     */
58
    public function getAllValues(): array
59
    {
60
        return array_merge(
61
            $this->constants,
62
            $this->dotenvVariables,
63
            $this->variables
64
        );
65
    }
66
67
    /**
68
     * @return Template[]
69
     */
70
    public function getTemplates(): array
71
    {
72
        return $this->templates;
73
    }
74
75
    public function createProcess(string $shellCommand): Process
76
    {
77
        return Process::fromShellCommandline($shellCommand);
78
    }
79
}
80