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 |
||
21 | class ToolbarListener implements EventSubscriberInterface |
||
22 | { |
||
23 | const DISABLED = 1; |
||
24 | |||
25 | const ENABLED = 2; |
||
26 | |||
27 | /** |
||
28 | * @var Environment |
||
29 | */ |
||
30 | protected $twig; |
||
31 | |||
32 | /** |
||
33 | * @var UrlGeneratorInterface |
||
34 | */ |
||
35 | protected $urlGenerator; |
||
36 | |||
37 | /** |
||
38 | * @var DataCollector |
||
39 | */ |
||
40 | protected $dataCollector; |
||
41 | |||
42 | /** |
||
43 | * @var AuthorizationChecker |
||
44 | */ |
||
45 | protected $authorizationChecker; |
||
46 | |||
47 | /** |
||
48 | * @var TokenStorageInterface |
||
49 | */ |
||
50 | protected $tokenStorage; |
||
51 | |||
52 | /** |
||
53 | * @var bool |
||
54 | */ |
||
55 | protected $enabled; |
||
56 | |||
57 | /** |
||
58 | * @var ContainerInterface |
||
59 | */ |
||
60 | private $container; |
||
61 | |||
62 | /** |
||
63 | * @var AdminRouteHelper |
||
64 | */ |
||
65 | protected $adminRouteHelper; |
||
66 | |||
67 | /** |
||
68 | * @var array |
||
69 | */ |
||
70 | protected $providerKeys; |
||
71 | |||
72 | /** |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $adminFirewallName; |
||
76 | |||
77 | /** |
||
78 | * ToolbarListener constructor. |
||
79 | * |
||
80 | * @param Environment $twig |
||
81 | * @param UrlGeneratorInterface $urlGenerator |
||
82 | * @param DataCollector $dataCollector |
||
83 | * @param AuthorizationChecker $authorizationChecker |
||
84 | * @param TokenStorageInterface $tokenStorage |
||
85 | * @param bool $enabled |
||
86 | * @param ContainerInterface $container |
||
87 | * @param AdminRouteHelper $adminRouteHelper |
||
88 | * @param array $providerKeys |
||
89 | * @param string $adminFirewallName |
||
90 | */ |
||
91 | public function __construct( |
||
114 | |||
115 | /** |
||
116 | * @return array |
||
117 | */ |
||
118 | 3 | public static function getSubscribedEvents() |
|
124 | |||
125 | /** |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function isEnabled() |
||
132 | |||
133 | /** |
||
134 | * @param FilterResponseEvent|ResponseEvent $event |
||
135 | */ |
||
136 | public function onKernelResponse($event) |
||
188 | |||
189 | /** |
||
190 | * Injects the admin toolbar into the given Response. |
||
191 | * |
||
192 | * @param Response $response A Response instance |
||
193 | */ |
||
194 | protected function injectToolbar(Response $response, Request $request) |
||
212 | } |
||
213 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..