Passed
Push — master ( 813977...bea400 )
by Dmitrij
01:59
created

BaseCommand::replaceTextsSequence()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
1
<?php
2
3
namespace HotRodCli\Commands;
4
5
use HotRodCli\Jobs\Module\ReplaceText;
6
use Symfony\Component\Console\Command\Command;
7
use HotRodCli\AppContainer;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class BaseCommand extends Command
12
{
13
    protected $appContainer;
14
15
    protected $jobs = [];
16
17
    protected $processors = [];
18
19
    /** @var  ReplaceText */
20
    protected $replaceTextJob;
21
22
    public function __construct(AppContainer $appContainer)
23
    {
24
        $this->appContainer = $appContainer;
25
        $this->replaceTextJob = $this->appContainer->resolve(ReplaceText::class);
26
27
        parent::__construct();
28
    }
29
30
    public function setJobs()
31
    {
32
        foreach ($this->jobs as $key => $job) {
33
            $this->jobs[$key] = $this->appContainer->resolve($key);
34
        }
35
    }
36
37
    public function setProcessors()
38
    {
39
        foreach ($this->processors as $key => $processor) {
40
            $this->processors[$key] = $this->appContainer->resolve($key);
41
        }
42
    }
43
44
    public function runProcessors(InputInterface $input, OutputInterface $output)
45
    {
46
        foreach ($this->processors as $processor) {
47
            $processor($input, $output);
48
        }
49
50
        return $this;
51
    }
52
53
    public function replaceTextsSequence(array $sequence, string $destination)
54
    {
55
        foreach ($sequence as $needle => $value) {
56
            $this->replaceTextJob->handle($needle, $value, $destination);
57
        }
58
59
        return $this;
60
    }
61
}
62