Completed
Push — master ( c3ef57...f7ee5f )
by Oleg
03:09
created

Micro::getContainerClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php /** Micro */
2
3
namespace Micro;
4
5
use Micro\base\Container;
6
use Micro\base\Dispatcher;
7
use Micro\base\IContainer;
8
use Micro\cli\Consoles\DefaultConsoleCommand;
9
use Micro\resolver\ConsoleResolver;
10
use Micro\resolver\HMVCResolver;
11
use Micro\web\IOutput;
12
use Micro\web\IRequest;
13
use Micro\web\Response;
14
15
/**
16
 * Micro class file.
17
 *
18
 * Base class for initialize MicroPHP, used as bootstrap framework.
19
 *
20
 * @author Oleg Lunegov <[email protected]>
21
 * @link https://github.com/lugnsk/micro
22
 * @copyright Copyright &copy; 2013 Oleg Lunegov
23
 * @license /LICENSE
24
 * @package micro
25
 * @version 1.0
26
 * @since 1.0
27
 */
28
class Micro
29
{
30
    /** @const string VERSION Version framework */
31
    const VERSION = '1.1';
32
33
34
    /** @var bool $loaded Micro loaded flag */
35
    private $loaded;
36
    /** @var bool $debug Debug-mode flag */
37
    private $debug = true;
38
    /** @var string $environment Application environment */
39
    private $environment = 'devel';
40
    /** @var float $startTime Time of start framework */
41
    private $startTime;
42
43
    /** @var IContainer $container Container is a container for components and options */
44
    protected $container;
45
    /** @var string $appDir */
46
    protected $appDir;
47
48
49
    /**
50
     * Initialize application
51
     *
52
     * @access public
53
     *
54
     * @param string $environment Application environment: devel , production , test, other
55
     * @param bool   $debug       Debug-mode flag
56
     *
57
     * @result void
58
     */
59
    public function __construct($environment = 'devel', $debug = true)
60
    {
61
        $this->environment = (string)$environment;
62
        $this->debug = (bool)$debug;
63
        $this->loaded = false;
64
65
        ini_set('display_errors', $this->debug);
66
67
        /** @TODO: add handler for fatal errors... */
68
69
        if ($this->debug) {
70
            $this->startTime = microtime(true);
71
        }
72
    }
73
74
    /**
75
     * Clone application
76
     *
77
     * @access public
78
     *
79
     * @return void
80
     */
81
    public function __clone()
82
    {
83
        if ($this->debug) { // start new timer
84
            $this->startTime = microtime(true);
85
        }
86
87
        $this->loaded = false; // deactivate loaded
88
        $this->container = null; // remove configured container
89
    }
90
91
    /**
92
     * Initialization container
93
     *
94
     * @access protected
95
     * @return void
96
     */
97
    protected function initializeContainer()
98
    {
99
        $class = $this->getContainerClass();
100
101
        if ($class) {
102
            $class = new $class;
103
        }
104
105
        $this->container = ($class instanceof IContainer) ? $class : new Container;
106
107
        $this->container->kernel = $this;
0 ignored issues
show
Bug introduced by
Accessing kernel on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
108
109
        $this->container->load($this->getConfig());
110
111
        if (false === $this->container->dispatcher) {
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
112
            $this->container->dispatcher = new Dispatcher;
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
113
        }
114
115
        $this->addListener('kernel.kill', function(array $params) {
116
            if ($params['container']->kernel->isDebug() && !$params['container']->request->isCli()) {
117
                // Add timer into page
118
                echo '<div class=debug_timer>', (microtime(true) - $this->getStartTime()), '</div>';
119
            }
120
        });
121
122
        $this->container->dispatcher->signal('kernel.boot', ['container' => $this->container]);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
123
    }
124
125
    /**
126
     * Running application
127
     *
128
     * @access public
129
     *
130
     * @param IRequest $request Request object
131
     *
132
     * @return Response
133
     * @throws \Exception
134
     */
135
    public function run(IRequest $request)
136
    {
137
        if (!$this->loaded) {
138
            $this->initializeContainer();
139
140
            $this->loaded = true;
141
        }
142
143
        $this->container->request = $request;
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
144
145
        $this->container->dispatcher->signal('kernel.request', ['container' => $this->container]);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
146
147
        try {
148
            return $this->doRun(); // run application
149
        } catch (\Exception $e) { // if not caught exception
150
            if ($this->debug) {
151
                $this->container->dispatcher->signal('kernel.exception', ['exception' => $e]);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
152
                throw $e;
153
            }
154
155
            return $this->doException($e); // run exception
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doException($e); of type Micro\Cli\Consoles\Defau...mand|Micro\Web\Response adds the type Micro\Cli\Consoles\DefaultConsoleCommand to the return on line 155 which is incompatible with the return type documented by Micro\Micro::run of type Micro\Web\Response.
Loading history...
156
        }
157
    }
158
159
    /**
160
     * Starting ...
161
     *
162
     * @access private
163
     *
164
     * @return \Micro\web\IResponse
165
     * @throws \Micro\base\Exception
166
     */
167
    private function doRun()
168
    {
169
        $resolver = $this->getResolver();
170
        $this->container->dispatcher->signal('kernel.router', ['resolver' => $resolver]);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
171
172
        $app = $resolver->getApplication();
173
        $this->container->dispatcher->signal('kernel.controller', ['application' => $app]);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
174
175
        $output = $app->action($resolver->getAction());
176
        if (!$output instanceof IOutput) {
177
            $response = $this->container->response ?: new Response;
0 ignored issues
show
Bug introduced by
Accessing response on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
178
            $response->setBody($output);
179
            $output = $response;
180
        }
181
        $this->container->dispatcher->signal('kernel.response', ['output' => $output]);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
182
183
        return $output;
184
    }
185
186
    /**
187
     * Do exception
188
     *
189
     * @access private
190
     *
191
     * @param \Exception $e Exception
192
     *
193
     * @return IOutput
194
     * @throws \Micro\base\Exception
195
     */
196
    private function doException(\Exception $e)
197
    {
198
        $output = $this->container->request->isCli() ? new DefaultConsoleCommand([]) : new Response();
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
199
200
        if ($this->container->request->isCli()) {
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
201
            $output->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
202
            $output->execute();
0 ignored issues
show
Bug introduced by
The method execute does only exist in Micro\Cli\Consoles\DefaultConsoleCommand, but not in Micro\Web\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
203
204
            return $output;
205
        }
206
207
        if (!$this->container->errorController) {
0 ignored issues
show
Bug introduced by
Accessing errorController on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
208
            $output->setBody('Option `errorController` not configured');
0 ignored issues
show
Bug introduced by
The method setBody does only exist in Micro\Web\Response, but not in Micro\Cli\Consoles\DefaultConsoleCommand.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
209
210
            return $output;
211
        }
212
        if (!$this->container->errorAction) {
0 ignored issues
show
Bug introduced by
Accessing errorAction on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
213
            $output->setBody('Option `errorAction` not configured');
214
215
            return $output;
216
        }
217
218
        $controller = $this->container->errorController;
0 ignored issues
show
Bug introduced by
Accessing errorController on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
219
        $action = $this->container->errorAction;
0 ignored issues
show
Bug introduced by
Accessing errorAction on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
220
221
        $this->container->request->setPost('error', $e);
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
222
223
        /** @var \Micro\mvc\controllers\IController $result */
224
        $result = new $controller($this->container, false);
225
        $result = $result->action($action);
226
227
        if ($result instanceof IOutput) {
228
            return $result;
229
        }
230
231
        $output->setBody($result);
0 ignored issues
show
Bug introduced by
It seems like $result defined by $result->action($action) on line 225 can also be of type object<Micro\Web\IResponse>; however, Micro\Web\Response::setBody() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
232
233
        return $output;
234
    }
235
236
    /**
237
     * Terminate application
238
     *
239
     * @access public
240
     *
241
     * @return void
242
     */
243
    public function terminate()
244
    {
245
        $this->container->dispatcher->signal('kernel.kill', ['container' => $this->container]);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
246
247
        $this->unloader();
248
    }
249
250
    /**
251
     * Add listener on event
252
     *
253
     * @access public
254
     *
255
     * @param string $listener listener name
256
     * @param mixed $event ['Object', 'method'] or callable
257
     * @param int|null $prior priority
258
     *
259
     * @return void
260
     */
261
    protected function addListener($listener, $event, $prior = null)
262
    {
263
        if (!is_string($listener) || !$this->container) {
264
            return false;
265
        }
266
267
        $this->container->dispatcher->addListener($listener, $event, $prior);
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
268
269
        return true;
270
    }
271
272
    // Methods for components
273
274
    /**
275
     * Default config path
276
     *
277
     * @return string
278
     */
279
    protected function getConfig()
280
    {
281
        return $this->getAppDir() . '/configs/main.php';
282
    }
283
284
    /**
285
     * Get full class name
286
     * @return string
287
     */
288
    protected function getContainerClass()
289
    {
290
        return '';
291
    }
292
293
    /**
294
     * Get resolver
295
     *
296
     * @access protected
297
     *
298
     * @param bool|false $isCli CLI or Web
0 ignored issues
show
Bug introduced by
There is no parameter named $isCli. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
299
     *
300
     * @return ConsoleResolver|HMVCResolver
301
     */
302
    protected function getResolver()
303
    {
304
        if ($this->container->request->isCli()) {
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
305
            return new ConsoleResolver($this->container);
306
        }
307
308
        return new HMVCResolver($this->container);
309
    }
310
311
    /**
312
     * Get status of debug
313
     *
314
     * @access public
315
     *
316
     * @return bool
317
     */
318
    public function isDebug()
319
    {
320
        return $this->debug;
321
    }
322
323
    /**
324
     * Get start time
325
     *
326
     * @access public
327
     *
328
     * @return float|null
329
     */
330
    public function getStartTime()
331
    {
332
        return $this->startTime;
333
    }
334
335
    // Methods helpers
336
337
    /**
338
     * Unloader subsystem
339
     *
340
     * @access public
341
     *
342
     * @return void
343
     */
344
    public function unloader()
345
    {
346
        if (false === $this->loaded) {
347
            return;
348
        }
349
350
        $this->container = null;
351
        $this->loaded = false;
352
    }
353
354
    /**
355
     * Get environment name
356
     *
357
     * @access public
358
     *
359
     * @return string
360
     */
361
    public function getEnvironment()
362
    {
363
        return $this->environment;
364
    }
365
366
    /**
367
     * Get components container
368
     *
369
     * @access public
370
     *
371
     * @return IContainer
372
     */
373
    public function getContainer()
374
    {
375
        return $this->container;
376
    }
377
378
    /**
379
     * Get character set
380
     *
381
     * @access public
382
     *
383
     * @return string
384
     */
385
    public function getCharset()
386
    {
387
        return 'UTF-8';
388
    }
389
390
    /**
391
     * Get application directory
392
     *
393
     * @return string
394
     */
395
    public function getAppDir()
396
    {
397
        if (!$this->appDir) {
398
            $this->appDir = dirname((new \ReflectionObject($this))->getFileName());
399
        }
400
401
        return $this->appDir;
402
    }
403
404
    /**
405
     * Get logs directory
406
     *
407
     * @return string
408
     */
409
    public function getLogDir()
410
    {
411
        return $this->getAppDir() . '/logs';
412
    }
413
414
    /**
415
     * Get cache directory
416
     *
417
     * @return string
418
     */
419
    public function getCacheDir()
420
    {
421
        return $this->getAppDir() . '/cache/' . $this->getEnvironment();
422
    }
423
}
424