Completed
Pull Request — master (#40)
by Wachter
10:02 queued 06:49
created

SeparateProcessExecutor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 1
cbo 4
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 14 2
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\Executor;
13
14
use Symfony\Component\Process\ProcessBuilder;
15
use Task\Execution\TaskExecutionInterface;
16
use Task\Runner\ExecutorInterface;
17
18
/**
19
 * Uses a separate process to start the executions via console-command.
20
 */
21
class SeparateProcessExecutor implements ExecutorInterface
22
{
23
    /**
24
     * @var string
25
     */
26
    private $consolePath;
27
28
    /**
29
     * @var string
30
     */
31
    private $environment;
32
33
    /**
34
     * @param string $consolePath
35
     * @param string $environment
36
     */
37 13
    public function __construct($consolePath, $environment)
38
    {
39 13
        $this->consolePath = $consolePath;
40 13
        $this->environment = $environment;
41 13
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function execute(TaskExecutionInterface $execution)
47
    {
48 2
        $process = ProcessBuilder::create(
49 2
            [$this->consolePath, 'task:execute', $execution->getUuid(), '-e ' . $this->environment]
50 2
        )->getProcess();
51
52 2
        $process->run();
53
54 2
        if (!$process->isSuccessful()) {
55 1
            throw new SeparateProcessException($process->getErrorOutput());
56
        }
57
58 1
        return $process->getOutput();
59
    }
60
}
61