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 namespace VojtaSvoboda\WebArtisan\Classes; |
||
| 7 | class CommandRunner |
||
| 8 | { |
||
| 9 | /** @var array $allowedCommands List of allowed commands loaded from Config. */ |
||
| 10 | protected $allowedCommands; |
||
| 11 | |||
| 12 | /** @var array $allowedPluginCommands List of allowed plugin commands. */ |
||
| 13 | protected $allowedPluginCommands; |
||
| 14 | |||
| 15 | /** @var Settings $settings */ |
||
| 16 | protected $settings; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * CommandRunner constructor. |
||
| 20 | * |
||
| 21 | * @param Settings $settings |
||
| 22 | */ |
||
| 23 | public function __construct(Settings $settings) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Run command and return true if Ok or string with error. |
||
| 32 | * |
||
| 33 | * @param string $command |
||
| 34 | * @param string $hash |
||
| 35 | * |
||
| 36 | * @return bool|string |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function run($command, $hash) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Run plugin command and return true if Ok or string with error. |
||
| 54 | * |
||
| 55 | * @param $command |
||
| 56 | * @param $plugin |
||
| 57 | * @param $hash |
||
| 58 | * |
||
| 59 | * @return bool|string |
||
| 60 | */ |
||
| 61 | View Code Duplication | public function runForPlugin($command, $plugin, $hash) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Run queued command and return true if Ok or string with error. |
||
| 79 | * |
||
| 80 | * @param string $command |
||
| 81 | * @param string $hash |
||
| 82 | * |
||
| 83 | * @return bool|string |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function runQueued($command, $hash) |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Check command and hash. |
||
| 101 | * |
||
| 102 | * @param string $command Command identifier. |
||
| 103 | * @param string $hash Security hash. |
||
| 104 | * @param string $plugin Plugin identifier (optional). |
||
| 105 | * |
||
| 106 | * @return bool|string |
||
| 107 | */ |
||
| 108 | public function check($command, $hash, $plugin = null) |
||
| 135 | } |
||
| 136 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.