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 |
||
19 | class Datatable |
||
20 | { |
||
21 | /** @var VersionEngine */ |
||
22 | private $versionEngine; |
||
23 | |||
24 | /** |
||
25 | * @var Factory |
||
26 | */ |
||
27 | private $viewFactory; |
||
28 | |||
29 | /** |
||
30 | * @var Repository |
||
31 | */ |
||
32 | private $configRepository; |
||
33 | |||
34 | /** |
||
35 | * Datatable constructor. |
||
36 | * @param VersionEngine $versionEngine The version engine that determines the correct version |
||
37 | * @param Factory $viewFactory The factory used to handle the view generation |
||
38 | * @param Repository $configRepository The repository responsible to get config values |
||
39 | */ |
||
40 | public function __construct(VersionEngine $versionEngine, Factory $viewFactory, Repository $configRepository) |
||
46 | |||
47 | /** |
||
48 | * Will create a new DataComposer with the given provider as implementation. |
||
49 | * |
||
50 | * @param Provider $provider The provider for the underlying data. |
||
51 | * |
||
52 | * @return ColumnComposer |
||
53 | */ |
||
54 | public function make(Provider $provider) |
||
59 | |||
60 | /** |
||
61 | * Will return a default DatatableView with no columns defined, but with the view and the version prepared. |
||
62 | * The user is responsible to populate the view with the wished columns, because they can not be derived from |
||
63 | * the server side column configuration. |
||
64 | * |
||
65 | * @param string $tableView the name of the table view to render |
||
66 | * @param string $scriptView the name of the script view to render |
||
67 | * |
||
68 | * @return DatatableView the view to work with |
||
69 | */ |
||
70 | View Code Duplication | public function view($tableView = null, $scriptView = null) |
|
82 | } |
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.