AbstractAent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 9 3
A run() 0 11 1
A __construct() 0 6 1
1
<?php
2
3
namespace TheAentMachine\Aent;
4
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Exception\CommandNotFoundException;
8
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
9
use Symfony\Component\Console\Input\ArgvInput;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\ConsoleOutput;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use TheAentMachine\Aent\Event\ReplyEvent;
14
use TheAentMachine\Aent\Event\VoidEvent;
15
use TheAentMachine\Helper\ReplyAggregator;
16
17
abstract class AbstractAent extends Application
18
{
19
    /** @var VoidEvent */
20
    private $voidEvent;
21
22
    /**
23
     * AbstractAent constructor.
24
     * @param string $name
25
     */
26
    public function __construct(string $name)
27
    {
28
        parent::__construct($name);
29
        $this->voidEvent = new VoidEvent();
30
        $this->add($this->voidEvent);
31
        $this->add(new ReplyEvent(new ReplyAggregator()));
32
    }
33
34
    /**
35
     * @param InputInterface|null $input
36
     * @param OutputInterface|null $output
37
     * @return int|void
38
     * @throws \Exception
39
     */
40
    public function run(InputInterface $input = null, OutputInterface $output = null)
41
    {
42
        $input = new ArgvInput();
43
        $output = new ConsoleOutput();
44
        $outputStyle = new OutputFormatterStyle('magenta');
45
        $output->getFormatter()->setStyle('info', $outputStyle);
46
        $outputStyle = new OutputFormatterStyle('black', 'magenta', ['bold']);
47
        $output->getFormatter()->setStyle('block', $outputStyle);
48
        $outputStyle = new OutputFormatterStyle('black', 'cyan', ['bold']);
49
        $output->getFormatter()->setStyle('altblock', $outputStyle);
50
        parent::run($input, $output);
51
    }
52
53
    /**
54
     * Overrides the Symfony "find" method to return a default command if no command is found.
55
     * @param string $name
56
     * @return Command
57
     */
58
    public function find($name)
59
    {
60
        try {
61
            if (!$this->has($name)) {
62
                return $this->voidEvent;
63
            }
64
            return parent::find($name);
65
        } catch (CommandNotFoundException $e) {
66
            return $this->voidEvent;
67
        }
68
    }
69
}
70