Passed
Push — master ( 47699c...d74cf0 )
by Rougin
01:47
created

Bootstrap::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 3
cp 0.6667
crap 1.037
rs 10
1
<?php
2
3
namespace App;
4
5
use Illuminate\Container\Container as IlluminateContainer;
0 ignored issues
show
Bug introduced by
The type Illuminate\Container\Container was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\Facade;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Facade was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Zapheus\Application;
8
use Zapheus\Bridge\Illuminate\Provider as IlluminateProvider;
0 ignored issues
show
Bug introduced by
The type Zapheus\Bridge\Illuminate\Provider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Zapheus\Container\CompositeContainer;
10
use Zapheus\Container\Container as WritableContainer;
11
use Zapheus\Container\ReflectionContainer;
12
use Zapheus\Provider\Configuration;
13
use Zapheus\Provider\FrameworkProvider;
14
15
use App\Application\Controllers\GreetController;
0 ignored issues
show
Bug introduced by
The type App\Application\Controllers\GreetController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
/**
18
 * Bootstrap Container
19
 *
20
 * @package Zapheus
21
 * @author  Rougin Royce Gutib <[email protected]>
22
 */
23
class Bootstrap extends CompositeContainer
24
{
25
    const ILLUMINATE_CONTAINER = 'Illuminate\Container\Container';
26
27
    const ILLUMINATE_PROVIDER = 'Zapheus\Bridge\Illuminate\Provider';
28
29
    /**
30
     * Static instance of the application container.
31
     *
32
     * @var \Zapheus\Container\ContainerInterface
33
     */
34
    protected static $container;
35
36
    /**
37
     * Path of the configurations directory.
38
     *
39
     * @var string
40
     */
41
    protected $config = 'app/config';
42
43
    /**
44
     * Full path of the root directory.
45
     *
46
     * @var string
47
     */
48
    protected $root;
49
50
    /**
51
     * An instance of a Container\WritableInterface.
52
     *
53
     * @var \Zapheus\Container\WritableInterface
54
     */
55
    protected $writable;
56
57
    /**
58
     * Initializes the container instance.
59
     *
60
     * @param string $root
61
     */
62 6
    public function __construct($root)
63
    {
64 6
        $this->writable = new WritableContainer;
65
66 6
        $this->configuration($this->root = $root);
0 ignored issues
show
Unused Code introduced by
The call to App\Bootstrap::configuration() has too many arguments starting with $this->root = $root. ( Ignorable by Annotation )

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

66
        $this->/** @scrutinizer ignore-call */ 
67
               configuration($this->root = $root);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
67
68
        // NOTE: If you want to autowire your classes, you may want
69
        // to use the ReflectionContainer class but it might have an
70
        // effect regarding the performance of the application. Just
71
        // uncomment lines 70 in order to use the mentioned instance.
72
73 6
        $this->add(new ReflectionContainer);
74
75
        // Define your dependencies below using $this->writable->set() method.
76
        // Documentation: $this->writable->set(string $id, mixed $concrete)
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
78
        // NOTE: If you enabled the ReflectionContainer above, you can
79
        // now enable to define controllers without setting it manually.
80
        // So you can comment line 79 if the said instance was enabled.
81
82
        // $this->writable->set(GreetController::class, new GreetController);
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
83 6
    }
84
85
    /**
86
     * Returns the writable container.
87
     *
88
     * @return \Zapheus\Container\WritableInterface
89
     */
90 6
    public function container()
91
    {
92 6
        return $this->writable;
93
    }
94
95
    /**
96
     * Prepares the providers and runs the application.
97
     *
98
     * @return \Zapheus\Application\ApplicationInterface
99
     */
100 6
    public function initialize()
101
    {
102
        // Loads the writable container.
103 6
        $container = $this->container();
104
105
        // Sets up the application with the container
106 6
        $app = new Application($container);
107
108
        // Loads all the available providers
109 6
        return $this->providers($app);
110
    }
111
112
    /**
113
     * Finds an entry of the container by its identifier and returns it.
114
     *
115
     * @param  string $id
116
     * @return mixed
117
     *
118
     * @throws \Zapheus\Container\Exception\NotFoundException
119
     * @throws \Zapheus\Container\Exception\ContainerException
120
     */
121 6
    public static function make($id)
122
    {
123 6
        return self::$container->get($id);
124
    }
125
126
    /**
127
     * Loads the configuration files from a specified path.
128
     *
129
     * @return \Zapheus\Container\WritableContainer
0 ignored issues
show
Bug introduced by
The type Zapheus\Container\WritableContainer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
130
     */
131 6
    protected function configuration()
132
    {
133 6
        $interface = (string) FrameworkProvider::CONFIG;
134
135 6
        $config = new Configuration;
136
137 6
        $config->load($this->root . $this->config, true);
0 ignored issues
show
Unused Code introduced by
The call to Zapheus\Provider\Configuration::load() has too many arguments starting with true. ( Ignorable by Annotation )

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

137
        $config->/** @scrutinizer ignore-call */ 
138
                 load($this->root . $this->config, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
138
139 6
        return $this->writable->set($interface, $config);
140
    }
141
142
    /**
143
     * Sets the providers for the application.
144
     *
145
     * @param  \Zapheus\Application $application
146
     * @return \Zapheus\Application
147
     */
148 6
    protected function providers(Application $application)
149
    {
150 6
        $config = $application->get(Application::CONFIGURATION);
151
152 6
        $zapheus = $config->get('app.providers.zapheus');
153
154 6
        foreach ((array) $zapheus as $provider) {
155 6
            $string = is_string($provider);
156
157 6
            $string && $provider = new $provider;
158
159 6
            $application->add($provider);
160 6
        }
161
162 6
        if (class_exists(self::ILLUMINATE_PROVIDER) === true) {
163
            $laravel = $config->get('app.providers.laravel', array());
164
165
            $application->add(new IlluminateProvider($laravel));
166
167
            $container = $application->get(self::ILLUMINATE_CONTAINER);
168
169
            Facade::setFacadeApplication($container);
170
        }
171
172 6
        $application->add(new FrameworkProvider($this));
173
174 6
        return static::$container = $application;
175
    }
176
}
177