Passed
Pull Request — master (#15)
by Anton
03:07
created

Dispatcher::route()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 8

Duplication

Lines 4
Ratio 14.81 %

Importance

Changes 0
Metric Value
dl 4
loc 27
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 0
1
<?php
2
3
/**
4
 * @package Cadmium\System
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace {
11
12
	use Modules\Extend, Utils\Map, Utils\Schema;
13
14
	class Dispatcher {
15
16
		/**
17
		 * Route a request to a handler
18
		 */
19
20
		public function route() {
21
22
			# Check installation
23
24 View Code Duplication
			if (null === ($data = Schema::get('System')->load())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
26
				Request::redirect(INSTALL_PATH . '/install.php');
27
			}
28
29
			# Connect to database
30
31
			DB::connect(...array_values($data['database']));
0 ignored issues
show
Bug introduced by
The call to connect() misses some required arguments starting with $user.
Loading history...
Documentation introduced by
array_values($data['database']) is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
33
			# Init addons
34
35
			Extend\Addons::init();
36
37
			# Get handler class by requested url
38
39
			$handler = Map::handler($url = new Url(Request::get('url')));
40
41
			$class = ((false !== $handler) ? $handler : 'Modules\Page');
42
43
			# ------------------------
44
45
			new $class($url);
46
		}
47
	}
48
}
49