Passed
Push — master ( 6512ce...41860c )
by Korotkov
02:02
created

Application   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 17
c 3
b 0
f 0
dl 0
loc 59
rs 10
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 7 2
A request() 0 3 1
A response() 0 3 1
A session() 0 3 1
A binding() 0 3 1
A config() 0 3 1
A cookie() 0 3 1
A setServices() 0 8 3
A objects() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Jagepard <[email protected]">
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Rudra\Container;
11
12
use Rudra\Container\Interfaces\{ApplicationInterface, ContainerInterface, RequestInterface, ResponseInterface};
13
use Rudra\Container\Traits\InstantiationsTrait;
14
15
class Application implements ApplicationInterface
16
{
17
    use InstantiationsTrait;
18
19
    private static ?ApplicationInterface $application = null;
20
21
    public function binding(): ContainerInterface
22
    {
23
        return $this->instantiate("binding", Container::class);
24
    }
25
26
    public function setServices(array $services): void
27
    {
28
        foreach ($services["contracts"] as $interface => $contract) {
29
            $this->binding()->set([$interface => $contract]);
30
        }
31
32
        foreach ($services["services"] as $name => $service) {
33
            $this->objects()->set([$name, $service]);
34
        }
35
    }
36
37
    public function objects(): ContainerInterface
38
    {
39
        return $this->instantiate("objects", DI::class, $this->binding());
40
    }
41
42
    public function cookie(): ContainerInterface
43
    {
44
        return $this->instantiate("cookie", Cookie::class);
45
    }
46
47
    public function session(): ContainerInterface
48
    {
49
        return $this->instantiate("session", Session::class);
50
    }
51
52
    public function config(): ContainerInterface
53
    {
54
        return $this->instantiate("config", Container::class);
55
    }
56
57
    public function request(): RequestInterface
58
    {
59
        return $this->instantiate("request", Request::class);
60
    }
61
62
    public function response(): ResponseInterface
63
    {
64
        return $this->instantiate("response", Response::class);
65
    }
66
67
    public static function run(): ApplicationInterface
68
    {
69
        if (!static::$application instanceof static) {
0 ignored issues
show
Bug introduced by
Since $application is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $application to at least protected.
Loading history...
70
            static::$application = new static();
71
        }
72
73
        return static::$application;
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::application could return the type null which is incompatible with the type-hinted return Rudra\Container\Interfaces\ApplicationInterface. Consider adding an additional type-check to rule them out.
Loading history...
74
    }
75
}
76