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 |
||
26 | class BlastCoreExtension extends Extension |
||
27 | { |
||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | public function load(array $configs, ContainerBuilder $container) |
||
32 | { |
||
33 | $config = $this->processConfiguration($this->getConfiguration([], $container), $configs); |
||
|
|||
34 | $this->initialize(); |
||
35 | $loader = $this->buildLoader($container); |
||
36 | |||
37 | // $this->loadParameters($container, $loader); |
||
38 | $this->loadServices($loader); |
||
39 | $this->loadCodeGenerators($container, $config); |
||
40 | $this->loadDataFixtures($container, $loader); |
||
41 | $this->loadBlasts($container, $loader); |
||
42 | $this->loadSecurity($container); |
||
43 | $this->loadSonataAdmin($container, $loader); |
||
44 | $this->loadListeners($container, $config); |
||
45 | $this->doLoad($container, $loader, $config); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @return self |
||
50 | */ |
||
51 | public function initialize() |
||
62 | |||
63 | /** |
||
64 | * the buildLoader returns the required FileLoader. |
||
65 | * |
||
66 | * @param ContainerBuilder $container |
||
67 | * |
||
68 | * @return FileLoader |
||
69 | */ |
||
70 | public function buildLoader(ContainerBuilder $container) |
||
74 | |||
75 | /** |
||
76 | * This method is called during the self::load() process, to add the logic related to SonataAdmin. |
||
77 | * |
||
78 | * @param FileLoader $loader |
||
79 | * |
||
80 | * @return self |
||
81 | */ |
||
82 | View Code Duplication | public function loadServices(FileLoader $loader) |
|
90 | |||
91 | /** |
||
92 | * This method is called after loading the services in the self::load() process, to load code generators. |
||
93 | * |
||
94 | * @param ContainerBuilder $container |
||
95 | * @param array $config |
||
96 | * |
||
97 | * @return self |
||
98 | */ |
||
99 | public function loadCodeGenerators(ContainerBuilder $container, array $config) |
||
103 | |||
104 | /** |
||
105 | * This method is called after loading the services in the self::load() process, to load data fixtures. |
||
106 | * |
||
107 | * @param ContainerBuilder $container |
||
108 | * @param FileLoader $loader |
||
109 | * |
||
110 | * @return self |
||
111 | */ |
||
112 | public function loadDataFixtures(ContainerBuilder $container, FileLoader $loader) |
||
116 | |||
117 | /** |
||
118 | * @param ContainerBuilder $container |
||
119 | * |
||
120 | * @return self |
||
121 | */ |
||
122 | public function loadBlasts(ContainerBuilder $container, FileLoader $loader) |
||
131 | |||
132 | /** |
||
133 | * @param ContainerBuilder $container |
||
134 | * |
||
135 | * @return self |
||
136 | */ |
||
137 | View Code Duplication | public function loadParameters(ContainerBuilder $container, FileLoader $loader) |
|
146 | |||
147 | /** |
||
148 | * This method is called at the end of the self::load() process, to add security related logic. |
||
149 | * |
||
150 | * @param ContainerBuilder $container |
||
151 | * |
||
152 | * @return self |
||
153 | */ |
||
154 | public function loadSecurity(ContainerBuilder $container) |
||
158 | |||
159 | /** |
||
160 | * This method is called at the end of the self::load() process, to add the logic related to SonataAdmin. |
||
161 | * |
||
162 | * @param ContainerBuilder $container |
||
163 | * @param FileLoader $loader |
||
164 | * |
||
165 | * @return self |
||
166 | */ |
||
167 | public function loadSonataAdmin(ContainerBuilder $container, FileLoader $loader) |
||
179 | |||
180 | /** |
||
181 | * This method is called during the self::load() process, to add the logic related to SonataAdmin. |
||
182 | * |
||
183 | * @param ContainerBuilder $container |
||
184 | * @param array $config |
||
185 | * |
||
186 | * @return self |
||
187 | */ |
||
188 | public function loadListeners(ContainerBuilder $container, array $config) |
||
192 | |||
193 | /** |
||
194 | * This method is called at the end of the self::load() process, to add any logic needed. |
||
195 | * |
||
196 | * @param ContainerBuilder $container |
||
197 | * @param FileLoader $loader |
||
198 | * @param array $config |
||
199 | * |
||
200 | * @return self |
||
201 | */ |
||
202 | public function doLoad(ContainerBuilder $container, FileLoader $loader, array $config) |
||
206 | |||
207 | /** |
||
208 | * @param string $var the parameter name |
||
209 | * @param ContainerBuilder $container |
||
210 | * @param string $dir |
||
211 | * @param string $file_name |
||
212 | * |
||
213 | * @return self |
||
214 | */ |
||
215 | protected function mergeParameter($var, $container, $dir, $file_name = 'blast.yml') |
||
235 | } |
||
236 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: