BackgroundProcessRunner::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 4
crap 2
1
<?php namespace Indatus\Dispatcher;
2
3
/**
4
 * This file is part of Dispatcher
5
 *
6
 * (c) Ben Kuhl <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
use Indatus\Dispatcher\Scheduling\ScheduledCommandInterface;
13
use Indatus\Dispatcher\Services\CommandService;
14
15
class BackgroundProcessRunner
16
{
17
    /**
18
     * @var \Indatus\Dispatcher\Services\CommandService
19
     */
20
    private $commandService;
21
22 5
    public function __construct(CommandService $commandService)
23
    {
24 5
        $this->commandService = $commandService;
25 5
    }
26
27
    /**
28
     * Run a scheduled command
29
     *
30
     * @param  \Indatus\Dispatcher\Scheduling\ScheduledCommandInterface $scheduledCommand
31
     * @param  array                                                    $arguments
32
     * @param  array                                                    $options
33
     * @return bool
34
     */
35 2
    public function run(
36
        ScheduledCommandInterface $scheduledCommand,
37
        array $arguments = [],
38
        array $options = [],
39
        Debugger $debugger = null
40
    ) {
41 2
        $runCommand = $this->commandService->getRunCommand($scheduledCommand, $arguments, $options);
42
43 2
        if (!is_null($debugger)) {
44 1
            $debugger->commandRun($scheduledCommand, $runCommand);
45 1
        }
46
47 2
        exec($runCommand);
48
49 2
        return true;
50
    }
51
}
52