| Conditions | 7 |
| Paths | 16 |
| Total Lines | 127 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 | /** |
||
| 56 | * Core files to be included into installation package |
||
| 57 | */ |
||
| 58 | $core_files = $this->get_core_files(); |
||
| 59 | /** |
||
| 60 | * Add modules that should be built-in into package |
||
| 61 | */ |
||
| 62 | $components_files = []; |
||
| 63 | $modules = $this->filter_and_add_components("$this->root/components/modules", $modules, $components_files); |
||
| 64 | $phar->addFromString('modules.json', _json_encode($modules)); |
||
| 65 | /** |
||
| 66 | * Add plugins that should be built-in into package |
||
| 67 | */ |
||
| 68 | $plugins = $this->filter_and_add_components("$this->root/components/plugins", $plugins, $components_files); |
||
| 69 | $phar->addFromString('plugins.json', _json_encode($plugins)); |
||
| 70 | /** |
||
| 71 | * Add themes that should be built-in into package |
||
| 72 | */ |
||
| 73 | $themes = $this->filter_and_add_components("$this->root/themes", $themes, $components_files); |
||
| 74 | $phar->addFromString('themes.json', _json_encode($themes)); |
||
| 75 | /** |
||
| 76 | * Joining system and components files |
||
| 77 | */ |
||
| 78 | $core_files = array_merge($core_files, $components_files); |
||
| 79 | /** |
||
| 80 | * Addition of files into package |
||
| 81 | */ |
||
| 82 | foreach ($core_files as $index => &$file) { |
||
| 83 | $phar->addFile($file, "fs/$index"); |
||
| 84 | $file = substr($file, $length); |
||
| 85 | } |
||
| 86 | unset($index, $file); |
||
| 87 | /** |
||
| 88 | * Addition of separate files into package |
||
| 89 | */ |
||
| 90 | $phar->addFromString('fs/'.count($core_files), $this->get_readme()); |
||
| 91 | $core_files[] = 'readme.html'; |
||
| 92 | $phar->addFromString( |
||
| 93 | 'languages.json', |
||
| 94 | _json_encode( |
||
| 95 | array_merge( |
||
| 96 | _substr(get_files_list("$this->root/core/languages", '/^.*?\.php$/i', 'f'), 0, -4) ?: [], |
||
| 97 | _substr(get_files_list("$this->root/core/languages", '/^.*?\.json$/i', 'f'), 0, -5) ?: [] |
||
| 98 | ) |
||
| 99 | ) |
||
| 100 | ); |
||
| 101 | $phar->addFromString( |
||
| 102 | 'db_engines.json', |
||
| 103 | _json_encode( |
||
| 104 | _substr(get_files_list("$this->root/core/engines/DB", '/^[^_].*?\.php$/i', 'f'), 0, -4) |
||
| 105 | ) |
||
| 106 | ); |
||
| 107 | /** |
||
| 108 | * Fixation of system files list (without components files), it is needed for future system updating |
||
| 109 | */ |
||
| 110 | $phar->addFromString( |
||
| 111 | 'fs/'.count($core_files), |
||
| 112 | _json_encode( |
||
| 113 | array_values( |
||
| 114 | array_diff( |
||
| 115 | $core_files, |
||
| 116 | _substr($components_files, $length) |
||
| 117 | ) |
||
| 118 | ) |
||
| 119 | ) |
||
| 120 | ); |
||
| 121 | $core_files[] = 'core/fs.json'; |
||
| 122 | unset($components_files, $length); |
||
| 123 | /** |
||
| 124 | * Addition of files, that are needed only for installation |
||
| 125 | */ |
||
| 126 | $phar->addFromString('fs/'.count($core_files), $this->get_htaccess()); |
||
| 127 | $core_files[] = '.htaccess'; |
||
| 128 | $phar->addFile("$this->root/config/main.php", 'fs/'.count($core_files)); |
||
| 129 | $core_files[] = 'config/main.php'; |
||
| 130 | $phar->addFile("$this->root/favicon.ico", 'fs/'.count($core_files)); |
||
| 131 | $core_files[] = 'favicon.ico'; |
||
| 132 | $phar->addFile("$this->root/.gitignore", 'fs/'.count($core_files)); |
||
| 133 | $core_files[] = '.gitignore'; |
||
| 134 | /** |
||
| 135 | * Flip array to have direct access to files by name during extracting and installation, and fixing of files list for installation |
||
| 136 | */ |
||
| 137 | $phar->addFromString( |
||
| 138 | 'fs.json', |
||
| 139 | _json_encode( |
||
| 140 | array_flip($core_files) |
||
| 141 | ) |
||
| 142 | ); |
||
| 143 | unset($core_files); |
||
| 144 | /** |
||
| 145 | * Addition of supplementary files, that are needed directly for installation process: installer with GUI interface, readme, license, some additional |
||
| 146 | * information about available languages, themes, current version of system |
||
| 147 | */ |
||
| 148 | $phar->addFile("$this->root/install.php", 'install.php'); |
||
| 149 | $phar->addFromString('readme.html', $this->get_readme()); |
||
| 150 | $phar->addFile("$this->root/license.txt", 'license.txt'); |
||
| 151 | $phar->addFile("$this->root/components/modules/System/meta.json", 'meta.json'); |
||
| 152 | $phar->setStub( |
||
| 153 | <<<STUB |
||
| 154 | <?php |
||
| 155 | if (PHP_SAPI == 'cli') { |
||
| 156 | Phar::mapPhar('cleverstyle_cms.phar'); |
||
| 157 | include 'phar://cleverstyle_cms.phar/install.php'; |
||
| 158 | } else { |
||
| 159 | Phar::webPhar(null, 'install.php'); |
||
| 160 | } |
||
| 161 | __HALT_COMPILER(); |
||
| 162 | STUB |
||
| 163 | ); |
||
| 164 | $phar->stopBuffering(); |
||
| 165 | return "Done! CleverStyle CMS $version"; |
||
| 166 | } |
||
| 167 | /** |
||
| 404 |