Passed
Push — 5.0 ( c16c04...6887da )
by Marc André
02:29
created

Core   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A start() 0 28 3
A __construct() 0 3 1
A getContext() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of the Cervo package.
5
 *
6
 * Copyright (c) 2010-2019 Nevraxe inc. & Marc André Audet <[email protected]>.
7
 *
8
 * @package   Cervo
9
 * @author    Marc André Audet <[email protected]>
10
 * @copyright 2010 - 2019 Nevraxe inc. & Marc André Audet
11
 * @license   See LICENSE.md  MIT
12
 * @link      https://github.com/Nevraxe/Cervo
13
 * @since     5.0.0
14
 */
15
16
declare(strict_types=1);
17
18
namespace Cervo;
19
20
use Cervo\Config\BaseConfig;
21
use Cervo\Exceptions\ControllerReflection\AlreadyInitialisedException;
22
23
24
/**
25
 * Core class for Cervo.
26
 *
27
 * @author Marc André Audet <[email protected]>
28
 */
29
final class Core
30
{
31
    /** @var bool */
32
    private $isInit = false;
33
34
    /** @var Context|null */
35
    private $context = null;
36
37
    public function __construct(?BaseConfig $config = null)
38
    {
39
        $this->context = new Context($config);
40
    }
41
42
    public function start()
43
    {
44
        if ($this->isInit === true) {
45
            throw new AlreadyInitialisedException;
46
        }
47
48
        $this->isInit = true;
49
50
        /** @var Events $events */
51
        $events = $this->getContext()->getSingletons()->get(Events::class);
52
53
        /** @var Router $router */
54
        $router = $this->getContext()->getSingletons()->get(Router::class);
55
56
        foreach ($this->getContext()->getModulesManager()->getAllModules() as [$vendor_name, $module_name, $path]) {
57
            $events->loadPath($path);
58
            $router->loadPath($path);
59
        }
60
61
        $events->fire('Cervo/System/Before');
62
63
        $route = $router->dispatch();
64
65
        $events->fire('Cervo/Route/Before');
66
        (new ControllerReflection($this->getContext(), $route))();
0 ignored issues
show
Bug introduced by
It seems like $this->getContext() can also be of type null; however, parameter $context of Cervo\ControllerReflection::__construct() does only seem to accept Cervo\Context, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        (new ControllerReflection(/** @scrutinizer ignore-type */ $this->getContext(), $route))();
Loading history...
67
        $events->fire('Cervo/Route/After');
68
69
        $events->fire('Cervo/System/After');
70
    }
71
72
    public function getContext(): ?Context
73
    {
74
        return $this->context;
75
    }
76
}
77