Conditions | 7 |
Paths | 16 |
Total Lines | 125 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
40 | function core ($modules = [], $plugins = [], $themes = [], $suffix = null) { |
||
41 | $suffix = $suffix ? "_$suffix" : ''; |
||
42 | $version = file_get_json("$this->root/components/modules/System/meta.json")['version']; |
||
43 | $target_file = "$this->target/CleverStyle_CMS_$version$suffix.phar.php"; |
||
44 | if (file_exists($target_file)) { |
||
45 | unlink($target_file); |
||
46 | } |
||
47 | $phar = new Phar($target_file); |
||
48 | unset($target_file); |
||
49 | $phar->startBuffering(); |
||
50 | $length = strlen("$this->root/"); |
||
51 | foreach (get_files_list("$this->root/install", false, 'f', true, true) as $file) { |
||
52 | $phar->addFile($file, substr($file, $length)); |
||
53 | } |
||
54 | unset($file); |
||
55 | $phar->addFile("$this->root/includes/img/logo.svg", 'logo.svg'); |
||
56 | /** |
||
57 | * Core files to be included into installation package |
||
58 | */ |
||
59 | $core_files = $this->get_core_files(); |
||
60 | /** |
||
61 | * Add modules that should be built-in into package |
||
62 | */ |
||
63 | $components_files = []; |
||
64 | $modules = $this->filter_and_add_components("$this->root/components/modules", $modules, $components_files); |
||
65 | $phar->addFromString('modules.json', _json_encode($modules)); |
||
66 | /** |
||
67 | * Add plugins that should be built-in into package |
||
68 | */ |
||
69 | $plugins = $this->filter_and_add_components("$this->root/components/plugins", $plugins, $components_files); |
||
70 | $phar->addFromString('plugins.json', _json_encode($plugins)); |
||
71 | /** |
||
72 | * Add themes that should be built-in into package |
||
73 | */ |
||
74 | $themes = $this->filter_and_add_components("$this->root/themes", $themes, $components_files); |
||
75 | $phar->addFromString('themes.json', _json_encode($themes)); |
||
76 | /** |
||
77 | * Joining system and components files |
||
78 | */ |
||
79 | $core_files = array_merge($core_files, $components_files); |
||
80 | /** |
||
81 | * Addition of files into package |
||
82 | */ |
||
83 | foreach ($core_files as $index => &$file) { |
||
84 | $phar->addFile($file, "fs/$index"); |
||
85 | $file = substr($file, $length); |
||
86 | } |
||
87 | unset($index, $file); |
||
88 | /** |
||
89 | * Addition of separate files into package |
||
90 | */ |
||
91 | $phar->addFromString( |
||
92 | 'languages.json', |
||
93 | _json_encode( |
||
94 | array_merge( |
||
95 | _substr(get_files_list("$this->root/core/languages", '/^.*?\.php$/i', 'f'), 0, -4) ?: [], |
||
96 | _substr(get_files_list("$this->root/core/languages", '/^.*?\.json$/i', 'f'), 0, -5) ?: [] |
||
97 | ) |
||
98 | ) |
||
99 | ); |
||
100 | $phar->addFromString( |
||
101 | 'db_engines.json', |
||
102 | _json_encode( |
||
103 | _substr(get_files_list("$this->root/core/engines/DB", '/^[^_].*?\.php$/i', 'f'), 0, -4) |
||
104 | ) |
||
105 | ); |
||
106 | /** |
||
107 | * Fixation of system files list (without components files), it is needed for future system updating |
||
108 | */ |
||
109 | $phar->addFromString( |
||
110 | 'fs/'.count($core_files), |
||
111 | _json_encode( |
||
112 | array_values( |
||
113 | array_diff( |
||
114 | $core_files, |
||
115 | _substr($components_files, $length) |
||
116 | ) |
||
117 | ) |
||
118 | ) |
||
119 | ); |
||
120 | $core_files[] = 'core/fs.json'; |
||
121 | unset($components_files, $length); |
||
122 | /** |
||
123 | * Addition of files, that are needed only for installation |
||
124 | */ |
||
125 | $phar->addFromString('fs/'.count($core_files), $this->get_htaccess()); |
||
126 | $core_files[] = '.htaccess'; |
||
127 | $phar->addFile("$this->root/config/main.php", 'fs/'.count($core_files)); |
||
128 | $core_files[] = 'config/main.php'; |
||
129 | $phar->addFile("$this->root/favicon.ico", 'fs/'.count($core_files)); |
||
130 | $core_files[] = 'favicon.ico'; |
||
131 | $phar->addFile("$this->root/.gitignore", 'fs/'.count($core_files)); |
||
132 | $core_files[] = '.gitignore'; |
||
133 | /** |
||
134 | * Flip array to have direct access to files by name during extracting and installation, and fixing of files list for installation |
||
135 | */ |
||
136 | $phar->addFromString( |
||
137 | 'fs.json', |
||
138 | _json_encode( |
||
139 | array_flip($core_files) |
||
140 | ) |
||
141 | ); |
||
142 | unset($core_files); |
||
143 | /** |
||
144 | * Addition of supplementary files, that are needed directly for installation process: installer with GUI interface, readme, license, some additional |
||
145 | * information about available languages, themes, current version of system |
||
146 | */ |
||
147 | $phar->addFile("$this->root/install.php", 'install.php'); |
||
148 | $phar->addFile("$this->root/license.txt", 'license.txt'); |
||
149 | $phar->addFile("$this->root/components/modules/System/meta.json", 'meta.json'); |
||
150 | $phar->setStub( |
||
151 | <<<STUB |
||
152 | <?php |
||
153 | if (PHP_SAPI == 'cli') { |
||
154 | Phar::mapPhar('cleverstyle_cms.phar'); |
||
155 | include 'phar://cleverstyle_cms.phar/install.php'; |
||
156 | } else { |
||
157 | Phar::webPhar(null, 'install.php'); |
||
158 | } |
||
159 | __HALT_COMPILER(); |
||
160 | STUB |
||
161 | ); |
||
162 | $phar->stopBuffering(); |
||
163 | return "Done! CleverStyle CMS $version"; |
||
164 | } |
||
165 | /** |
||
383 |