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 |
||
| 15 | class Files_Handler { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The Plugins_Handler object. |
||
| 19 | * |
||
| 20 | * @var Plugins_Handler |
||
| 21 | */ |
||
| 22 | private $plugins_handler = null; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The Version_Selector object. |
||
| 26 | * |
||
| 27 | * @var Version_Selector |
||
| 28 | */ |
||
| 29 | private $version_selector = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The constructor. |
||
| 33 | * |
||
| 34 | * @param Plugins_Handler $plugins_handler The Plugins_Handler object. |
||
| 35 | * @param Version_Selector $version_selector The Version_Selector object. |
||
| 36 | */ |
||
| 37 | public function __construct( $plugins_handler, $version_selector ) { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Adds the version of a package file to the $jetpack_packages_filemap global |
||
| 44 | * array so that we can load the most recent version. |
||
| 45 | * |
||
| 46 | * @param string $file_identifier Unique id to file assigned by composer based on package name and filename. |
||
| 47 | * @param string $version Version of the file. |
||
| 48 | * @param string $path Absolute path to the file so that we can load it. |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function enqueue_package_file( $file_identifier, $version, $path ) { |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Creates a path to the plugin's filemap. The filemap filename is the filename |
||
| 69 | * generated by Jetpack Autoloader version >= 2.0. |
||
| 70 | * |
||
| 71 | * @param String $plugin_path The plugin path. |
||
| 72 | * |
||
| 73 | * @return String The filemap path |
||
| 74 | */ |
||
| 75 | public function create_filemap_path( $plugin_path ) { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Initializes the filemap. |
||
| 81 | */ |
||
| 82 | View Code Duplication | public function set_file_paths() { |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Include latest version of all enqueued files. |
||
| 101 | */ |
||
| 102 | public function file_loader() { |
||
| 112 | } |
||
| 113 |