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 ToolbarListener implements EventSubscriberInterface |
||
20 | { |
||
21 | const DISABLED = 1; |
||
22 | |||
23 | const ENABLED = 2; |
||
24 | |||
25 | /** |
||
26 | * @var \Twig_Environment |
||
27 | */ |
||
28 | protected $twig; |
||
29 | |||
30 | /** |
||
31 | * @var UrlGeneratorInterface |
||
32 | */ |
||
33 | protected $urlGenerator; |
||
34 | |||
35 | /** |
||
36 | * @var DataCollector |
||
37 | */ |
||
38 | protected $dataCollector; |
||
39 | |||
40 | /** |
||
41 | * @var AuthorizationChecker |
||
42 | */ |
||
43 | protected $authorizationChecker; |
||
44 | |||
45 | /** |
||
46 | * @var TokenStorageInterface |
||
47 | */ |
||
48 | protected $tokenStorage; |
||
49 | |||
50 | /** |
||
51 | * @var bool |
||
52 | */ |
||
53 | protected $enabled; |
||
54 | |||
55 | /** |
||
56 | * @var ContainerInterface |
||
57 | */ |
||
58 | private $container; |
||
59 | |||
60 | /** |
||
61 | * @var AdminRouteHelper |
||
62 | */ |
||
63 | protected $adminRouteHelper; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $providerKeys; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $adminFirewallName; |
||
74 | |||
75 | /** |
||
76 | * ToolbarListener constructor. |
||
77 | * |
||
78 | * @param \Twig_Environment $twig |
||
79 | * @param UrlGeneratorInterface $urlGenerator |
||
80 | * @param DataCollector $dataCollector |
||
81 | * @param AuthorizationChecker $authorizationChecker |
||
82 | * @param TokenStorageInterface $tokenStorage |
||
83 | * @param bool $enabled |
||
84 | * @param ContainerInterface $container |
||
85 | * @param AdminRouteHelper $adminRouteHelper |
||
86 | * @param array $providerKeys |
||
87 | * @param string $adminFirewallName |
||
88 | */ |
||
89 | public function __construct( |
||
112 | |||
113 | /** |
||
114 | * @return array |
||
115 | */ |
||
116 | public static function getSubscribedEvents() |
||
122 | |||
123 | /** |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function isEnabled() |
||
130 | |||
131 | /** |
||
132 | * @param FilterResponseEvent $event |
||
133 | */ |
||
134 | public function onKernelResponse(FilterResponseEvent $event) |
||
182 | |||
183 | /** |
||
184 | * Injects the admin toolbar into the given Response. |
||
185 | * |
||
186 | * @param Response $response A Response instance |
||
187 | */ |
||
188 | protected function injectToolbar(Response $response, Request $request) |
||
207 | } |
||
208 |
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..