These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | /* |
||
4 | |||
5 | Usage: |
||
6 | |||
7 | Copy clone.php in <xoops_root> |
||
8 | Change current working directory to <xoops_root> |
||
9 | Update mappings as per new modulename. |
||
10 | |||
11 | php -q clone.php |
||
12 | |||
13 | */ |
||
14 | |||
15 | // ########################################################## |
||
16 | // Define your mapping here |
||
17 | // ########################################################## |
||
18 | $patterns = array( |
||
19 | // first one must be module directory name |
||
20 | 'smartpartner' => 'smartclient', |
||
21 | 'partner' => 'client', |
||
22 | 'SMARTPARTNER' => 'SMARTCLIENT', |
||
23 | 'SmartPartner' => 'SmartClient', |
||
24 | 'Smart Partner' => 'Smart Client', |
||
25 | 'SPARTNER' => 'SCLIENT', |
||
26 | 'Smartpartner' => 'Smartclient', |
||
27 | 'Partner' => 'Client', |
||
28 | 'Partenaire' => 'Client', |
||
29 | 'partenaire' => 'client' |
||
30 | ); |
||
31 | |||
32 | $patKeys = array_keys($patterns); |
||
33 | $patValues = array_values($patterns); |
||
34 | |||
35 | // work around for PHP < 5.0.x |
||
36 | if (!function_exists('file_put_contents')) { |
||
37 | /** |
||
38 | * @param $filename |
||
39 | * @param $data |
||
40 | * @param bool $file_append |
||
41 | */ |
||
42 | function file_put_contents($filename, $data, $file_append = false) |
||
43 | { |
||
44 | $fp = fopen($filename, (!$file_append ? 'w+' : 'a+')); |
||
45 | if (!$fp) { |
||
46 | trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); |
||
47 | |||
48 | return; |
||
49 | } |
||
50 | fwrite($fp, $data); |
||
51 | fclose($fp); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | // recursive clonning script |
||
56 | /** |
||
57 | * @param $path |
||
58 | * @throws |
||
59 | */ |
||
60 | function cloneFileFolder($path) |
||
61 | { |
||
62 | global $patKeys; |
||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
63 | global $patValues; |
||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
64 | |||
65 | $newPath = str_replace($patKeys[0], $patValues[0], $path); |
||
0 ignored issues
–
show
$newPath is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
66 | $newPath = str_replace($patKeys[1], $patValues[1], $path); |
||
67 | |||
68 | if (is_dir($path)) { |
||
69 | // create new dir |
||
70 | // mkdir($newPath); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
71 | View Code Duplication | if (!@mkdir($newPath) && !is_dir($newPath)) { |
|
0 ignored issues
–
show
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. ![]() |
|||
72 | throw Exception("Couldn't create this directory: " . $newPath); |
||
73 | } |
||
74 | |||
75 | // check all files in dir, and process it |
||
76 | if ($handle = opendir($path)) { |
||
77 | while ($file = readdir($handle)) { |
||
78 | if ($file !== '.' && $file !== '..') { |
||
79 | cloneFileFolder("$path/$file"); |
||
80 | } |
||
81 | } |
||
82 | closedir($handle); |
||
83 | } |
||
84 | } else { |
||
85 | if (preg_match('/(.jpg|.gif|.png|.zip)$/i', $path)) { |
||
86 | copy($path, $newPath); |
||
87 | } else { |
||
88 | // file, read it |
||
89 | $content = file_get_contents($path); |
||
90 | $content = str_replace($patKeys, $patValues, $content); |
||
91 | file_put_contents($newPath, $content); |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | |||
96 | cloneFileFolder('modules/smartpartner'); |
||
97 | |||
98 | echo "Happy cloning...\n"; |
||
99 | echo 'check directory modules/' . $patterns['smartpartner'] . " for cloned module \n"; |
||
100 | echo "Consider modifying new module by editing language/english/modinfo.php and assets/images/logo_module.png manually (if you care)\n"; |
||
101 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.