Passed
Push — master ( 998a95...21763d )
by Federico
02:41
created

requirer.php ➔ requireComponents()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 3
b 0
f 0
nc 4
nop 3
dl 0
loc 11
rs 9.2
1
<?php
2
	function requireComponent( $_path, $_local = true, $_stack = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $_stack is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3
		$path = getJFolder($_path, $_local, debug_backtrace());
4
		if(file_exists($path) && isPhp($path))
5
			jRequire($path, false, 0);
6
		else
7
			requireError($_path);
8
	}
9
	function requireComponents( $_path, $_local = true, $_stack = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $_stack is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
10
		$path = getJFolder($_path, $_local, debug_backtrace());
11
		if(file_exists($path)) {
12
			$files = subFolderFile($path);
13
			foreach ($files as $i) {
14
				if(isPhp($path."/".$i))
15
					requireComponent($path."/".$i, false, 0);
16
			}
17
		} else
18
			requireError($_path);
19
	}
20
	function requireError( $_path ) {
21
		global $jConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
22
		if( $jConfig->DEBUG == 1 )
23
			echo "Error load ($_path)<br>";
24
	}
25
	function isPhp ( $_file ) {
26
		if(!is_file($_file)) return false;
27
		$info = pathinfo($_file);
28
		return ($info["extension"] == "php") || ($info["extension"] == "PHP");
29
	}
30
	function requireModules( $_path, $_local = true, $_stack = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $_stack is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
		$path = getJFolder($_path, $_local, debug_backtrace());
32
		$subFolders = subFolderDir($path);
33
		foreach ($subFolders as $i) {
34
			requireComponents($path."/".$i, false, 0);
35
		}
36
	}
37
	function jRequire( $_path, $_local = true, $_stack = null ) {
38
		$path = getJFolder($_path, $_local, debug_backtrace());
39
		require_once( $path );
40
	}
41
	function getJFolder( $_path, $_local, $_stack ) {
42
		if($_local) {
43
			$stackInfo = $_stack;
44
			$folder = dirname($stackInfo[0]["file"]);
45
			$file = "$folder/$_path";
46
		} else
47
			$file = $_path;
48
		return $file;
49
	}
50
?>
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...
51