Test Failed
Push — master ( c51706...f968f3 )
by Anton
01:54
created

SeriesExecutor::run()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7.5375

Importance

Changes 0
Metric Value
cc 7
nc 5
nop 2
dl 0
loc 30
ccs 14
cts 18
cp 0.7778
crap 7.5375
rs 8.5066
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Executor;
9
10
use Deployer\Console\Output\Informer;
11
use Deployer\Exception\NonFatalException;
12
use Deployer\Host\Localhost;
13
use Deployer\Task\Context;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class SeriesExecutor implements ExecutorInterface
18
{
19
    /**
20
     * @var InputInterface
21
     */
22
    private $input;
23
24
    /**
25
     * @var OutputInterface
26
     */
27
    private $output;
28
29
    /**
30
     * @var Informer
31
     */
32
    private $informer;
33
34 3
    public function __construct(
35
        InputInterface $input,
36
        OutputInterface $output,
37
        Informer $informer
38
    ) {
39 3
        $this->input = $input;
40 3
        $this->output = $output;
41 3
        $this->informer = $informer;
42 3
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 3
    public function run(array $tasks, array $hosts)
48
    {
49 3
        $localhost = new Localhost();
50 3
        foreach ($tasks as $task) {
51 3
            $success = true;
52 3
            $this->informer->startTask($task);
53
54 3
            if ($task->isLocal()) {
55 1
                $task->run(new Context($localhost, $this->input, $this->output));
56
            } else {
57 2
                foreach ($hosts as $host) {
58 2
                    if ($task->shouldBePerformed($host)) {
59
                        try {
60 2
                            $task->run(new Context($host, $this->input, $this->output));
61
                        } catch (NonFatalException $exception) {
62
                            $success = false;
63
                            $this->informer->taskException($exception, $host);
64
                        }
65 2
                        $this->informer->endOnHost($host->getHostname());
66
                    }
67
                }
68
            }
69
70 3
            if ($success) {
71 3
                $this->informer->endTask($task);
72
            } else {
73
                $this->informer->taskError();
74
            }
75
        }
76 3
    }
77
}
78