Runner::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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