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 = strtolower(basename($root)); |
45
|
|
|
$partials = explode('-', $vendor_name); |
46
|
|
|
$camel_case_partials = []; |
47
|
|
|
foreach ($partials as $partial) { |
48
|
|
|
$camel_case_partials[] = ucfirst(strtolower($partial)); |
49
|
|
|
} |
50
|
|
|
$camel_case = implode('_', $camel_case_partials); |
51
|
|
|
$snake_case = implode('_', $partials); |
52
|
|
|
|
53
|
|
|
$files = [ |
54
|
|
|
'/wpb.php', |
55
|
|
|
'/bootstrap/app.php', |
56
|
|
|
'/includes/class-wpb-activator.php', |
57
|
|
|
'/includes/class-wpb-deactivator.php', |
58
|
|
|
'/includes/class-wpb-i18n.php', |
59
|
|
|
'/includes/class-wpb-loader.php', |
60
|
|
|
'/includes/class-wpb.php', |
61
|
|
|
'/admin/class-wpb-admin.php', |
62
|
|
|
'/admin/partials/wpb-admin-display.php', |
63
|
|
|
'/admin/css/wpb-admin.css', |
64
|
|
|
'/admin/js/wpb-admin.js', |
65
|
|
|
'/public/class-wpb-public.php', |
66
|
|
|
'/public/partials/wpb-public-display.php', |
67
|
|
|
'/public/css/wpb-public.css', |
68
|
|
|
'/public/js/wpb-public.js', |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
foreach ($files as $file) { |
72
|
|
|
$file = $root.$file; |
73
|
|
|
if(file_exists($file)) { |
74
|
|
|
$contents = file_get_contents($file); |
75
|
|
|
$contents = str_replace('wpb_', $snake_case.'_', $contents); |
76
|
|
|
$contents = str_replace('wpb', $vendor_name, $contents); |
77
|
|
|
$contents = str_replace('WPB_APP_ROOT', strtoupper($camel_case).'_APP_ROOT', $contents); |
78
|
|
|
$contents = str_replace('WPB_FILE', strtoupper($camel_case).'_FILE', $contents); |
79
|
|
|
$contents = str_replace('WPB_PATH', strtoupper($camel_case).'_PATH', $contents); |
80
|
|
|
$contents = str_replace('WPB_INCLUDES', strtoupper($camel_case).'_INCLUDES', $contents); |
81
|
|
|
$contents = str_replace('WPB_URL', strtoupper($camel_case).'_URL', $contents); |
82
|
|
|
$contents = str_replace('WPB_ASSETS', strtoupper($camel_case).'_ASSETS', $contents); |
83
|
|
|
$contents = str_replace('WPB', $camel_case, $contents); |
84
|
|
|
file_put_contents( |
85
|
|
|
$file, |
86
|
|
|
$contents |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$dir = dirname($file); |
90
|
|
|
$fileName = basename($file); |
91
|
|
|
$newFileName = str_replace('wpb', $vendor_name, $fileName); |
92
|
|
|
if($fileName != $newFileName) { |
93
|
|
|
rename($file, $dir.'/'.$newFileName.'.php'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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.