Proxy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 23
c 2
b 0
f 1
dl 0
loc 81
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setApp() 0 4 1
A getCommand() 0 3 1
A setCommand() 0 4 1
A execute() 0 18 1
A setBootstrap() 0 4 1
1
<?php
2
/**
3
 * Named proxy
4
 * User: moyo
5
 * Date: 13/12/2017
6
 * Time: 4:10 PM
7
 */
8
9
namespace Carno\Console;
10
11
use Carno\Console\Chips\Dumps;
12
use Carno\Console\Chips\EVKit;
13
use Carno\Console\Contracts\Programme;
14
use Carno\Container\DI;
15
use function Carno\Coroutine\async;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Throwable;
20
21
class Proxy extends Command
22
{
23
    use EVKit;
24
    use Dumps;
25
26
    /**
27
     * @var Bootstrap
28
     */
29
    private $bootstrap = null;
30
31
    /**
32
     * @var string
33
     */
34
    private $target = null;
35
36
    /**
37
     * @var Based
38
     */
39
    private $ref = null;
40
41
    /**
42
     * @param string $name
43
     * @return static
44
     */
45
    public function setApp(string $name) : self
46
    {
47
        $this->bootstrap->app()->named($name);
48
        return $this;
49
    }
50
51
    /**
52
     * @param Bootstrap $bootstrap
53
     * @return static
54
     */
55
    public function setBootstrap(Bootstrap $bootstrap) : self
56
    {
57
        $this->bootstrap = $bootstrap;
58
        return $this;
59
    }
60
61
    /**
62
     * @param string $class
63
     * @return static
64
     */
65
    public function setCommand(string $class) : self
66
    {
67
        $this->target = $class;
68
        return $this;
69
    }
70
71
    /**
72
     * @return Based
73
     */
74
    public function getCommand() : Programme
75
    {
76
        return $this->ref ?? $this->ref = DI::object($this->target);
77
    }
78
79
    /**
80
     * @param InputInterface $input
81
     * @param OutputInterface $output
82
     * @return int
83
     */
84
    public function execute(InputInterface $input, OutputInterface $output)
85
    {
86
        $this->bootstrap->app()->inputs($input);
87
        $this->bootstrap->kernel();
88
89
        $ex = 0;
90
91
        async(function () {
92
            yield $this->getCommand()->execute($this->bootstrap);
93
        })->catch(function (Throwable $e) use (&$ex) {
94
            $ex = 1;
95
            $this->failure($e);
96
            $this->exits();
97
        });
98
99
        $this->loops();
100
101
        return $ex;
102
    }
103
}
104