Runner   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 20
c 3
b 0
f 0
dl 0
loc 34
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 2
A __construct() 0 3 1
A returnError() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chinstrap\Core\Console;
6
7
use Psr\Container\ContainerInterface;
8
use Psy\Shell as Psysh;
9
use Symfony\Component\Console\Application;
10
11
final class Runner
12
{
13
    private ContainerInterface $container;
14
15
    public function __construct(ContainerInterface $container)
16
    {
17
        $this->container = $container;
18
    }
19
20
    private function returnError(\Throwable $err): void
21
    {
22
        $msg = "Unable to run - " . $err->getMessage();
23
        $msg .= "\n" . $err->__toString();
24
        $msg .= "\n";
25
        echo $msg;
26
    }
27
28
    public function __invoke(): void
29
    {
30
        try {
31
            $console = $this->container->get(Application::class);
32
            $console->add($this->container->get(\Chinstrap\Core\Console\Commands\FlushCache::class));
33
            $console->add(
34
                new \Chinstrap\Core\Console\Commands\Shell(
35
                    $this->container,
36
                    $this->container->get(Psysh::class)
37
                )
38
            );
39
            $console->add($this->container->get(\Chinstrap\Core\Console\Commands\Server::class));
40
            $console->add($this->container->get(\Chinstrap\Core\Console\Commands\GenerateIndex::class));
41
            $console->add($this->container->get(\Chinstrap\Core\Console\Commands\GenerateSitemap::class));
42
            $console->run();
43
        } catch (\Throwable $err) {
44
            $this->returnError($err);
45
        }
46
    }
47
}
48