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 |
||
| 34 | View Code Duplication | class JsController extends Controller { |
|
|
|
|||
| 35 | |||
| 36 | /** @var IAppData */ |
||
| 37 | protected $appData; |
||
| 38 | |||
| 39 | /** @var ITimeFactory */ |
||
| 40 | protected $timeFactory; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $appName |
||
| 44 | * @param IRequest $request |
||
| 45 | * @param IAppData $appData |
||
| 46 | * @param ITimeFactory $timeFactory |
||
| 47 | */ |
||
| 48 | public function __construct($appName, IRequest $request, IAppData $appData, ITimeFactory $timeFactory) { |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @PublicPage |
||
| 57 | * @NoCSRFRequired |
||
| 58 | * |
||
| 59 | * @param string $fileName css filename with extension |
||
| 60 | * @param string $appName css folder name |
||
| 61 | * @return FileDisplayResponse|NotFoundResponse |
||
| 62 | */ |
||
| 63 | public function getJs($fileName, $appName) { |
||
| 80 | } |
||
| 81 |
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.