Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 29 | class Installer |
||
| 30 | { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * An array of directories to be made writable |
||
| 34 | */ |
||
| 35 | const WRITABLE_DIRS = [ |
||
| 36 | 'logs', |
||
| 37 | 'tmp', |
||
| 38 | 'tmp/cache', |
||
| 39 | 'tmp/cache/models', |
||
| 40 | 'tmp/cache/persistent', |
||
| 41 | 'tmp/cache/views', |
||
| 42 | 'tmp/sessions', |
||
| 43 | 'tmp/tests' |
||
| 44 | ]; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Does some routine installation tasks so people don't have to. |
||
| 48 | * |
||
| 49 | * @param \Composer\Script\Event $event The composer event object. |
||
| 50 | * @throws \Exception Exception raised by validator. |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | public static function postInstall(Event $event) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Create the config/app.php file if it does not exist. |
||
| 94 | * |
||
| 95 | * @param string $dir The application's root directory. |
||
| 96 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 97 | * @return void |
||
| 98 | */ |
||
| 99 | View Code Duplication | public static function createAppConfig($dir, $io) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Create the config/.env file if it does not exist. |
||
| 111 | * |
||
| 112 | * @param string $dir The application's root directory. |
||
| 113 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 114 | * @return void |
||
| 115 | */ |
||
| 116 | View Code Duplication | public static function createDotEnvConfig($dir, $io) |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Create the `logs` and `tmp` directories. |
||
| 128 | * |
||
| 129 | * @param string $dir The application's root directory. |
||
| 130 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 131 | * @return void |
||
| 132 | */ |
||
| 133 | public static function createWritableDirectories($dir, $io) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Set globally writable permissions on the "tmp" and "logs" directory. |
||
| 146 | * |
||
| 147 | * This is not the most secure default, but it gets people up and running quickly. |
||
| 148 | * |
||
| 149 | * @param string $dir The application's root directory. |
||
| 150 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 151 | * @return void |
||
| 152 | */ |
||
| 153 | public static function setFolderPermissions($dir, $io) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Set the security.salt value in the application's config file. |
||
| 193 | * |
||
| 194 | * @param string $dir The application's root directory. |
||
| 195 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 196 | * @return void |
||
| 197 | */ |
||
| 198 | public static function setSecuritySalt($dir, $io) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Set the security.salt value in a given file |
||
| 206 | * |
||
| 207 | * @param string $dir The application's root directory. |
||
| 208 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 209 | * @param string $newKey key to set in the file |
||
| 210 | * @param string $file A path to a file relative to the application's root |
||
| 211 | * @return void |
||
| 212 | */ |
||
| 213 | View Code Duplication | public static function setSecuritySaltInFile($dir, $io, $newKey, $file) |
|
| 234 | |||
| 235 | /** |
||
| 236 | * Set the APP_NAME value in a given file |
||
| 237 | * |
||
| 238 | * @param string $dir The application's root directory. |
||
| 239 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 240 | * @param string $appName app name to set in the file |
||
| 241 | * @param string $file A path to a file relative to the application's root |
||
| 242 | * @return void |
||
| 243 | */ |
||
| 244 | View Code Duplication | public static function setAppNameInFile($dir, $io, $appName, $file) |
|
| 264 | } |
||
| 265 |