requirer.php ➔ requireModules()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
  function requireComponent( $_path, $_local = true ) {
3
    $path = getJFolder($_path, $_local, debug_backtrace());
4
    if(file_exists($path) && isPhp($path))
5
      jRequire($path, false, 0);
0 ignored issues
show
Unused Code introduced by
The call to jRequire() has too many arguments starting with 0.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
6
    else
7
      requireError($_path);
8
  }
9
  function requireComponents( $_path, $_local = true ) {
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);
16
    } else
17
      requireError($_path);
18
  }
19
  function requireError( $_path ) {
20
    global $DEBUG;
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...
21
    if( $DEBUG == 1 )
22
      echo "Error load ($_path)<br>";
23
  }
24
  function isPhp ( $_file ) {
25
    if(!is_file($_file)) return false;
26
    $info = pathinfo($_file);
27
    return ($info["extension"] == "php") || ($info["extension"] == "PHP");
28
  }
29
  function requireModules( $_path, $_local = true ) {
30
    $path = getJFolder($_path, $_local, debug_backtrace());
31
    $subFolders = subFolderDir($path);
32
    foreach ($subFolders as $i)
33
      requireComponents("$path/$i", false);
34
  }
35
  function jRequire( $_path, $_local = true ) {
36
    $path = getJFolder($_path, $_local, debug_backtrace());
37
    require_once( $path );
38
  }
39
  function getJFolder( $_path, $_local, $_stack ) {
40
    if($_local) {
41
      $stackInfo = $_stack;
42
      $folder = dirname($stackInfo[0]["file"]);
43
      $file = "$folder/$_path";
44
    } else
45
      $file = $_path;
46
    return $file;
47
  }
48
  function requireModulesList( $_path ) {
49
    if(!file_exists($_path))
50
      return;
51
    $data = file_get_contents($_path);
52
    $data = json_decode($data);
53
    if($data === NULL)
54
      throw new Exception("Error in the file format [$_path]", 1);
55
    foreach ($data as $item) {
56
      if(substr($item, -1) == "*")
57
        requireModules(substr($item, 0, -2), false);
58
      else {
59
        $path = getJFolder($item, false, debug_backtrace());
60
        requireComponents("$path", false);
61
      }
62
    }
63
  }
64
?>
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...
65