Passed
Push — master ( 572619...0f2431 )
by Federico
03:18
created

JConfig   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 45
rs 10
wmc 9
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A import() 0 8 2
A overlayConnection() 0 3 1
A overlayMisc() 0 3 1
A obj2array() 0 11 2
A importObject() 0 4 2
1
<?php
2
	class JConfig {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
		public $connection;
4
		public $all;
5
		public $DEBUG;
6
		public $pages;
7
		public function __construct() {
8
			$this->connection["enable"]		= false;
9
			$this->connection["user"]			= "";
10
			$this->connection["password"] = "";
11
			$this->connection["database"] = "";
12
			$this->connection["server"]		= "";
13
			$this->all		= "";
14
			$this->DEBUG	= 0;
15
			$this->pages	= [];
16
		}
17
		public function import( $_path, $_type = "misc" ) {
18
			$data = file_get_contents($_path);
19
			$data = json_decode($data);
20
			if( $_type == "connection" )
21
				$this->overlayConnection($data);
22
			else
23
				$this->overlayMisc($data);
24
		}
25
		protected function overlayConnection( $_data ) {
26
			$this->connection = $this->obj2array($_data);
27
		}
28
		protected function overlayMisc( $_data ) {
29
			$this->importObject($_data);
30
		}
31
		protected function obj2array ( &$_instance ) {
32
			$clone	= (array) $_instance;
33
			$return	= [];
34
			$return['___SOURCE_KEYS_'] = $clone;
35
			while ( list ($key, $value) = each ($clone) ) {
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
36
				$temp		= explode ("\0", $key);
37
				$newkey	= $temp[count($temp)-1];
38
				$return[$newkey] = &$return['___SOURCE_KEYS_'][$key];
39
			}
40
			return $return;
41
		}
42
		protected function importObject( $_object ) {
43
			foreach (get_object_vars($_object) as $key => $value)
44
				$this->$key = $value;
45
		}
46
	}
47
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
48