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 |
||
27 | final class AuthSuccessAction |
||
28 | { |
||
29 | /** |
||
30 | * @var Environment |
||
31 | */ |
||
32 | private $twig; |
||
33 | |||
34 | /** |
||
35 | * @var RouterInterface |
||
36 | */ |
||
37 | private $router; |
||
38 | |||
39 | /** |
||
40 | * @var SessionManagerInterface |
||
41 | */ |
||
42 | private $sessionManager; |
||
43 | |||
44 | /** |
||
45 | * @var EventDispatcherInterface |
||
46 | */ |
||
47 | private $eventDispatcher; |
||
48 | |||
49 | View Code Duplication | public function __construct( |
|
60 | |||
61 | /** |
||
62 | * @throws LoaderError |
||
63 | * @throws RuntimeError |
||
64 | * @throws SyntaxError |
||
65 | */ |
||
66 | public function __invoke(): Response |
||
89 | |||
90 | /** |
||
91 | * Generates a URL from the given parameters. |
||
92 | * |
||
93 | * @param string $route The name of the route |
||
94 | * @param array $parameters An array of parameters |
||
95 | * @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface) |
||
96 | * |
||
97 | * @return string The generated URL |
||
98 | */ |
||
99 | private function generateUrl(string $route, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string |
||
103 | } |
||
104 |
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.