DumpFileSubstitution   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A substitute() 0 10 1
A __construct() 0 12 1
1
<?php declare(strict_types=1);
2
3
namespace Cocotte\Shell\EnvironmentSubstitution;
4
5
use Cocotte\Console\Style;
6
use Cocotte\Filesystem\Filesystem;
7
use Cocotte\Shell\ProcessRunner;
8
use Symfony\Component\Process\Process;
9
10
final class DumpFileSubstitution implements SubstitutionStrategy
11
{
12
    /**
13
     * @var string
14
     */
15
    private $filename;
16
17
    /**
18
     * @var string
19
     */
20
    private $contents;
21
22
    /**
23
     * @var Style
24
     */
25
    private $style;
26
27
    /**
28
     * @var ProcessRunner
29
     */
30
    private $processRunner;
31
32
    /**
33
     * @var Filesystem
34
     */
35
    private $filesystem;
36
37
    public function __construct(
38
        string $filename,
39
        string $contents,
40
        Style $style,
41
        ProcessRunner $processRunner,
42
        Filesystem $filesystem
43
    ) {
44
        $this->filename = $filename;
45
        $this->contents = $contents;
46
        $this->style = $style;
47
        $this->processRunner = $processRunner;
48
        $this->filesystem = $filesystem;
49
    }
50
51
    public function substitute(Process $envSubstProcess)
52
    {
53
        $this->style->verbose('Substituting environment in STDIN and dumping to '.$this->filename);
54
55
        $envSubstProcess->setInput($this->contents);
56
        $this->processRunner->mustRun($envSubstProcess);
57
58
        $this->filesystem->dumpFile(
59
            $this->filename,
60
            $envSubstProcess->getOutput()
61
        );
62
    }
63
64
}