Completed
Push — master ( 5df011...747e00 )
by Changwan
03:50
created

Application   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 10
cts 18
cp 0.5556
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A execute() 0 5 1
A setAsGlobal() 0 6 1
A boot() 0 8 2
1
<?php
2
namespace Wandu\Foundation;
3
4
use Wandu\DI\Container;
5
use Wandu\Foundation\Contracts\KernelInterface;
6
7
class Application extends Container
8
{
9
    const NAME = "Wandu";
10
    const VERSION = "3.1-dev";
11
12
    /** @var \Wandu\Foundation\Contracts\KernelInterface */
13
    protected $kernel;
14
15
    /** @var \Wandu\Foundation\Application */
16
    public static $app;
17
18
    /**
19
     * @param \Wandu\Foundation\Contracts\KernelInterface $kernel
20
     */
21 4
    public function __construct(KernelInterface $kernel)
22
    {
23 4
        parent::__construct();
24 4
        $this->instance(KernelInterface::class, $this->kernel = $kernel);
25 4
        $this->alias('kernel', KernelInterface::class);
26 4
        $this->setAsGlobal();
27 4
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function boot()
33
    {
34
        if (!$this->isBooted) {
35
            $this->kernel->boot($this);
36
            parent::boot();
37
        }
38
        return $this;
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44
    public function execute()
45
    {
46
        $this->boot();
47
        return $this->kernel->execute($this);
48
    }
49
50
    /**
51
     * @return \Wandu\Foundation\Application
52
     */
53 4
    public function setAsGlobal()
54
    {
55 4
        $oldApp = static::$app;
56 4
        static::$app = $this;
57 4
        return $oldApp;
58
    }
59
}
60