1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodexShaper\WP; |
4
|
|
|
|
5
|
|
|
use Composer\Script\Event; |
6
|
|
|
|
7
|
|
|
class ComposerScripts |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Handle the post-install Composer event. |
11
|
|
|
* |
12
|
|
|
* @param \Composer\Script\Event $event |
13
|
|
|
* @return void |
14
|
|
|
*/ |
15
|
|
|
public static function postInstall(Event $event) |
16
|
|
|
{ |
17
|
|
|
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Handle the post-update Composer event. |
22
|
|
|
* |
23
|
|
|
* @param \Composer\Script\Event $event |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public static function postUpdate(Event $event) |
27
|
|
|
{ |
28
|
|
|
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Handle the post-autoload-dump Composer event. |
33
|
|
|
* |
34
|
|
|
* @param \Composer\Script\Event $event |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public static function postAutoloadDump(Event $event) |
38
|
|
|
{ |
39
|
|
|
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php'; |
40
|
|
|
|
41
|
|
|
$dir = $event->getComposer()->getConfig()->get('vendor-dir').'/../'; |
|
|
|
|
42
|
|
|
$root = dirname($event->getComposer()->getConfig()->get('vendor-dir')); |
43
|
|
|
|
44
|
|
|
$vendor_name = basename($root); |
45
|
|
|
$partials = explode('-', $vendor_name); |
46
|
|
|
// $camel_case_partials = array_filter($partials, function($partial){ |
47
|
|
|
// return ucfirst($partial); |
48
|
|
|
// }); |
49
|
|
|
$camel_case_partials = []; |
50
|
|
|
foreach ($partials as $partial) { |
51
|
|
|
$camel_case_partials[] = ucfirst(strtolower($partial)); |
52
|
|
|
} |
53
|
|
|
// $snake_case_partials = array_filter($partials, function($partial){ |
54
|
|
|
// return strtolower($partial); |
55
|
|
|
// }); |
56
|
|
|
$snake_case_partials = []; |
57
|
|
|
foreach ($partials as $partial) { |
58
|
|
|
$snake_case_partials[] = strtolower($partial); |
59
|
|
|
} |
60
|
|
|
$camel_case = implode('_', $camel_case_partials); |
61
|
|
|
$snake_case = implode('_', $snake_case_partials); |
62
|
|
|
|
63
|
|
|
$files = [ |
64
|
|
|
'/wpb.php', |
65
|
|
|
'/bootstrap/app.php', |
66
|
|
|
'/includes/class-wpb-framework-activator.php', |
67
|
|
|
'/includes/class-wpb-framework-deactivator.php', |
68
|
|
|
'/includes/class-wpb-framework-i18n.php', |
69
|
|
|
'/includes/class-wpb-framework-loader.php', |
70
|
|
|
'/includes/class-wpb-framework.php', |
71
|
|
|
'/admin/class-wpb-framework-admin.php', |
72
|
|
|
'/admin/partials/wpb-framework-admin-display.php', |
73
|
|
|
'/admin/css/wpb-framework-admin.css', |
74
|
|
|
'/admin/js/wpb-framework-admin.js', |
75
|
|
|
'/public/class-wpb-framework-public.php', |
76
|
|
|
'/public/partials/wpb-framework-public-display.php', |
77
|
|
|
'/public/css/wpb-framework-public.css', |
78
|
|
|
'/public/js/wpb-framework-public.js', |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
foreach ($files as $file) { |
82
|
|
|
$file = $root.$file; |
83
|
|
|
if(file_exists($file)) { |
84
|
|
|
$contents = file_get_contents($file); |
85
|
|
|
$contents = str_replace('wpb_', $snake_case.'_', $contents); |
86
|
|
|
$contents = str_replace('wpb', $vendor_name, $contents); |
87
|
|
|
$contents = str_replace('WPB', $camel_case, $contents); |
88
|
|
|
file_put_contents( |
89
|
|
|
$file, |
90
|
|
|
$contents |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$dir = dirname($file); |
94
|
|
|
$fileName = basename($file); |
95
|
|
|
$newFileName = str_replace('wpb', $vendor_name, $fileName); |
96
|
|
|
rename($file, $dir.'/'.$newFileName.'.php'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.