Application   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 63
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A boot() 0 6 1
A setContainer() 0 4 1
A getContainer() 0 12 2
A run() 0 15 2
1
<?php
2
3
namespace Ramro;
4
5
use League\Container\Container;
6
use League\Container\ContainerAwareInterface;
7
use League\Container\ContainerInterface;
8
use League\Container\ReflectionContainer;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Ramro\Providers\HttpMessageServiceProvider;
12
use Ramro\Providers\RouteServiceProvider;
13
use Zend\Diactoros\Response\EmitterInterface;
14
15
class Application implements ContainerAwareInterface
16
{
17
    /**
18
     * @var \League\Container\ContainerInterface
19
     */
20
    protected $container;
21
22
    public function __construct()
23
    {
24
        $this->boot();
25
    }
26
27
    /**
28
     * Set a container
29
     *
30
     * @param \League\Container\ContainerInterface $container
31
     */
32
    public function setContainer(ContainerInterface $container)
33
    {
34
        $this->container = $container;
35
    }
36
37
    /**
38
     * Get the container
39
     *
40
     * @return \League\Container\ContainerInterface
41
     */
42
    public function getContainer()
43
    {
44
        if (isset($this->container)) {
45
            return $this->container;
46
        }
47
48
        $container = new Container;
49
        $container->delegate(new ReflectionContainer());
50
        $this->setContainer($container);
51
52
        return $container;
53
    }
54
55
    protected function boot()
56
    {
57
        $container = $this->getContainer();
58
        $container->addServiceProvider(HttpMessageServiceProvider::class);
59
        $container->addServiceProvider(RouteServiceProvider::class);
60
    }
61
62
    public function run()
63
    {
64
        try {
65
            $response = $this->container->get('route')->dispatch(
66
                $this->container->get(ServerRequestInterface::class),
67
                $this->container->get(ResponseInterface::class)
68
            );
69
70
            return $this->container->get(EmitterInterface::class)->emit($response);
71
72
        } catch (\Exception $exception) {
73
            // register exception handler which returns PSR-7 Response
74
            throw $exception;
75
        }
76
    }
77
}
78