Yarak::call()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 4
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak;
4
5
use Phalcon\DI;
6
use Phalcon\DiInterface;
7
use Phalcon\Di\FactoryDefault;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\Console\Output\NullOutput;
10
use Symfony\Component\Console\Output\BufferedOutput;
11
12
class Yarak
13
{
14
    /**
15
     * Call a Yarak console command.
16
     *
17
     * @param string         $command
18
     * @param array          $arguments Argument array.
19
     * @param FactoryDefault $di        DI, may be necessary for php 5.6.
20
     * @param bool           $debug     If true, use and return buffered output.
21
     */
22
    public static function call(
23
        $command,
24
        array $arguments = [],
25
        DiInterface $di = null,
26
        $debug = false
27
    ) {
28
        $di = is_null($di) ? DI::getDefault() : $di;
29
30
        $kernel = $di->get('yarak');
31
32
        $input = new ArrayInput(['command' => $command] + $arguments);
33
34
        if ($debug) {
35
            $kernel->handle($input, $output = new BufferedOutput());
36
37
            return $output;
38
        }
39
40
        $kernel->handle($input, new NullOutput());
41
    }
42
}
43