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 | public static function createAppConfig($dir, $io) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Create the `logs` and `tmp` directories. |
||
| 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 | public static function createWritableDirectories($dir, $io) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Set globally writable permissions on the "tmp" and "logs" directory. |
||
| 129 | * |
||
| 130 | * This is not the most secure default, but it gets people up and running quickly. |
||
| 131 | * |
||
| 132 | * @param string $dir The application's root directory. |
||
| 133 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 134 | * @return void |
||
| 135 | */ |
||
| 136 | public static function setFolderPermissions($dir, $io) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Set the security.salt value in the application's config file. |
||
| 175 | * |
||
| 176 | * @param string $dir The application's root directory. |
||
| 177 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 178 | * @return void |
||
| 179 | */ |
||
| 180 | public static function setSecuritySalt($dir, $io) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Set the security.salt value in a given file |
||
| 188 | * |
||
| 189 | * @param string $dir The application's root directory. |
||
| 190 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 191 | * @param string $newKey key to set in the file |
||
| 192 | * @param string $file A path to a file relative to the application's root |
||
| 193 | * @return void |
||
| 194 | */ |
||
| 195 | View Code Duplication | public static function setSecuritySaltInFile($dir, $io, $newKey, $file) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Set the APP_NAME value in a given file |
||
| 219 | * |
||
| 220 | * @param string $dir The application's root directory. |
||
| 221 | * @param \Composer\IO\IOInterface $io IO interface to write to console. |
||
| 222 | * @param string $appName app name to set in the file |
||
| 223 | * @param string $file A path to a file relative to the application's root |
||
| 224 | * @return void |
||
| 225 | */ |
||
| 226 | View Code Duplication | public static function setAppNameInFile($dir, $io, $appName, $file) |
|
| 246 | } |
||
| 247 |