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 |
||
8 | use League\Pipeline\Pipeline; |
||
9 | use Operador\Contracts\StageInterface; |
||
10 | |||
11 | class RepositoryPipeline |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * Repositorio Detectado |
||
16 | */ |
||
17 | public function run($eloquentClasses) |
||
35 | View Code Duplication | public function runTwo($eloquentClasses) |
|
36 | { |
||
37 | |||
38 | |||
39 | $tables = (new Pipeline) |
||
40 | ->pipe(new DatabaseRender) |
||
41 | ->pipe(new DatabaseMount); |
||
42 | |||
43 | // Returns 21 |
||
44 | $entitys = $pipeline->process(10); |
||
45 | |||
46 | |||
47 | |||
48 | // Re-usable Pipelines |
||
49 | // Because the PipelineInterface is an extension of the StageInterface pipelines can be re-used as stages. This creates a highly composable model to create complex execution patterns while keeping the cognitive load low. |
||
50 | |||
51 | // For example, if we'd want to compose a pipeline to process API calls, we'd create something along these lines: |
||
52 | |||
53 | $databaseEntity = (new Pipeline) |
||
54 | ->pipe(new ExecuteHttpRequest) // 2 |
||
55 | ->pipe(new ParseJsonResponse); // 3 |
||
56 | |||
57 | $pipeline = (new Pipeline) |
||
58 | ->pipe(new ConvertToPsr7Request) // 1 |
||
59 | ->pipe($processApiRequest) // (2,3) |
||
60 | ->pipe(new ConvertToResponseDto); // 4 |
||
61 | |||
62 | $pipeline->process(new DeleteBlogPost($postId)); |
||
64 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.