SeriesExecutor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.3%

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
ccs 21
cts 23
cp 0.913
wmc 8
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B run() 0 30 7
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 11
    public function __construct(
35
        InputInterface $input,
36
        OutputInterface $output,
37
        Informer $informer
38
    ) {
39 11
        $this->input = $input;
40 11
        $this->output = $output;
41 11
        $this->informer = $informer;
42 11
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 11
    public function run(array $tasks, array $hosts)
48
    {
49 11
        $localhost = new Localhost();
50 11
        foreach ($tasks as $task) {
51 11
            $success = true;
52 11
            $this->informer->startTask($task);
53
54 11
            if ($task->isLocal()) {
55 3
                $task->run(new Context($localhost, $this->input, $this->output));
56
            } else {
57 10
                foreach ($hosts as $host) {
58 10
                    if ($task->shouldBePerformed($host)) {
59
                        try {
60 10
                            $task->run(new Context($host, $this->input, $this->output));
61 1
                        } catch (NonFatalException $exception) {
62
                            $success = false;
63
                            $this->informer->taskException($exception, $host);
64
                        }
65 10
                        $this->informer->endOnHost($host->getHostname());
66
                    }
67
                }
68
            }
69
70 11
            if ($success) {
71 11
                $this->informer->endTask($task);
72
            } else {
73 11
                $this->informer->taskError();
74
            }
75
        }
76 11
    }
77
}
78