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 |
||
23 | class Routing extends Command |
||
24 | { |
||
25 | public function configure() |
||
37 | |||
38 | /** |
||
39 | * @param InputInterface $input |
||
40 | * @param OutputInterface $output |
||
41 | * |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function execute(InputInterface $input, OutputInterface $output) |
||
54 | |||
55 | /** |
||
56 | * @param $method |
||
57 | * @param $path |
||
58 | * @param InputInterface $input |
||
59 | * @param OutputInterface $output |
||
60 | */ |
||
61 | protected function test($method, $path, InputInterface $input, OutputInterface $output) |
||
|
|||
62 | { |
||
63 | $request = new ServerRequest($method, $path, [ |
||
64 | 'User-Agent' => 'FastD Console/'.version(), |
||
65 | ]); |
||
66 | |||
67 | $response = app()->handleRequest($request); |
||
68 | |||
69 | $output->writeln(sprintf('Method: <info>%s</info>', $method)); |
||
70 | $output->writeln(sprintf('Path: <info>%s</info>', $path).PHP_EOL); |
||
71 | |||
72 | $headersLIne = ''; |
||
73 | |||
74 | View Code Duplication | foreach ($response->getHeaders() as $name => $header) { |
|
75 | $headersLIne .= $name.': '.$response->getHeaderLine($name).PHP_EOL; |
||
76 | } |
||
77 | |||
78 | $body = (string) $response->getBody(); |
||
79 | $body = json_encode(json_decode($body, true), JSON_PRETTY_PRINT); |
||
80 | $output->writeln($headersLIne.PHP_EOL.$body); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param InputInterface $input |
||
85 | * @param OutputInterface $output |
||
86 | */ |
||
87 | protected function render(InputInterface $input, OutputInterface $output) |
||
120 | } |
||
121 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.