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 |
||
14 | class Extension extends \Twig_Extension implements GlobalsInterface |
||
|
|||
15 | { |
||
16 | /** |
||
17 | * {@inheritDoc} |
||
18 | */ |
||
19 | 1 | public function getGlobals() |
|
27 | |||
28 | /** |
||
29 | * {@inheritDoc} |
||
30 | */ |
||
31 | 1 | public function getFilters() |
|
63 | |||
64 | /** |
||
65 | * {@inheritDoc} |
||
66 | */ |
||
67 | 1 | public function getFunctions() |
|
84 | |||
85 | /** |
||
86 | * Takes an iterable and returns an object that allow mapping, sorting, etc. |
||
87 | * |
||
88 | * @param $iterable |
||
89 | * @return Itertools\lib\Interfaces\FiniteIterableInterface|Itertools\lib\IterableIterator |
||
90 | */ |
||
91 | 1 | public function it($iterable) |
|
95 | |||
96 | /** |
||
97 | * Takes an iterable and returns another iterable that is unique. |
||
98 | * |
||
99 | * @param array|string|\Iterator $iterable |
||
100 | * @param mixed $strategy |
||
101 | * @return Itertools\lib\UniqueIterator |
||
102 | * @deprecated |
||
103 | */ |
||
104 | public function unique($iterable, $strategy = null) |
||
108 | |||
109 | /** |
||
110 | * Reduce an iterable to a single value |
||
111 | * |
||
112 | * Simple examples: |
||
113 | * {{ [1,2,3]|reduce }} --> 6 |
||
114 | * {{ [1,2,3]|reduce('max') }} --> 3 |
||
115 | * |
||
116 | * Sro example to get the prices for all items in the basket: |
||
117 | * {{ transaction_snapshot.Basket.Items|map('TotalPrice.Amount')|reduce }} |
||
118 | * |
||
119 | * @param array|string|\Iterator $iterable |
||
120 | * @param string|\Closure $closure |
||
121 | * @param mixed $initializer |
||
122 | * @return mixed |
||
123 | * @deprecated |
||
124 | */ |
||
125 | public function reduce($iterable, $closure = 'add', $initializer = null) |
||
129 | |||
130 | /** |
||
131 | * Make an iterator that returns consecutive groups from the |
||
132 | * $iterable. Generally, the $iterable needs to already be sorted on |
||
133 | * the same key function. |
||
134 | * |
||
135 | * @param array|string|\Iterator $iterable |
||
136 | * @param string|\Closure $strategy |
||
137 | * @param boolean $sort |
||
138 | * @return Itertools\lib\GroupbyIterator |
||
139 | * @deprecated |
||
140 | */ |
||
141 | public function groupBy($iterable, $strategy, $sort = true) |
||
145 | |||
146 | /** |
||
147 | * Make an iterator that returns values from $iterable where the |
||
148 | * $strategy determines that the values are not empty. |
||
149 | * |
||
150 | * @param array|string|\Iterator $iterable |
||
151 | * @param null $strategy |
||
152 | * @return Itertools\lib\FilterIterator |
||
153 | * @deprecated |
||
154 | */ |
||
155 | public function filter($iterable, $strategy = null) |
||
159 | |||
160 | /** |
||
161 | * Make an iterator that returns the values from $iterable sorted by |
||
162 | * $strategy. |
||
163 | * |
||
164 | * @param array|string|\Iterator $iterable |
||
165 | * @param string|\Closure $strategy |
||
166 | * @param bool $reverse |
||
167 | * @return Itertools\lib\SortedIterator |
||
168 | * @deprecated |
||
169 | */ |
||
170 | public function sorted($iterable, $strategy = null, $reverse = false) |
||
174 | |||
175 | /** |
||
176 | * Make an iterator that applies $func to every entry in the $iterables. |
||
177 | * |
||
178 | * @param array|string|\Iterator $iterable |
||
179 | * @param string|\Closure $strategy |
||
180 | * @return Itertools\lib\MapIterator |
||
181 | * @deprecated |
||
182 | */ |
||
183 | public function map($iterable, $strategy) |
||
187 | |||
188 | /** |
||
189 | * Make an iterator returning values from $iterable and keys from |
||
190 | * $strategy. |
||
191 | * |
||
192 | * @param array|string|\Iterator $iterable |
||
193 | * @param string|\Closure $strategy |
||
194 | * @return Itertools\lib\MapByIterator |
||
195 | * @deprecated |
||
196 | */ |
||
197 | public function mapBy($iterable, $strategy) |
||
201 | |||
202 | |||
203 | /** |
||
204 | * Returns a reduction closure |
||
205 | * |
||
206 | * Any parameters provided, beyond $name, are passed directly to the underlying |
||
207 | * reduction. This can be used to, for example, provide a $glue when using join. |
||
208 | * |
||
209 | * @param string $name |
||
210 | * @return \Closure |
||
211 | * @throws \InvalidArgumentException |
||
212 | */ |
||
213 | 4 | View Code Duplication | public function reducing($name) |
224 | |||
225 | /** |
||
226 | * Returns a mapping closure |
||
227 | * |
||
228 | * Any parameters provided, beyond $name, are passed directly to the underlying |
||
229 | * mapping. This can be used to, for example, provide a $glue when using join. |
||
230 | * |
||
231 | * @param string $name |
||
232 | * @return \Closure |
||
233 | * @throws \InvalidArgumentException |
||
234 | */ |
||
235 | 2 | View Code Duplication | public function mapping($name) |
246 | |||
247 | /** |
||
248 | * Returns a filter closure |
||
249 | * |
||
250 | * Any parameters provided, beyond $name, are passed directly to the underlying |
||
251 | * filter. This can be used to, for example, provide a $glue when using join. |
||
252 | * |
||
253 | * @param string $name |
||
254 | * @return \Closure |
||
255 | * @throws \InvalidArgumentException |
||
256 | */ |
||
257 | 2 | View Code Duplication | public function filtering($name) |
269 | |||
270 | /** |
||
271 | * Make an iterator that returns values from $iterable where the |
||
272 | * $strategy determines that the values are not empty. |
||
273 | * |
||
274 | * @param array|string|\Iterator $iterable |
||
275 | * @param string|\Closure $strategy |
||
276 | * @return Itertools\lib\FilterIterator |
||
277 | * @deprecated Use filter instead! |
||
278 | */ |
||
279 | public function deprecatedFilterBy($iterable, $strategy) |
||
283 | |||
284 | /** |
||
285 | * Make an iterator that returns consecutive groups from the |
||
286 | * $iterable. Generally, the $iterable needs to already be sorted on |
||
287 | * the same key function. |
||
288 | * |
||
289 | * @param array|string|\Iterator $iterable |
||
290 | * @param string|\Closure $strategy |
||
291 | * @return Itertools\lib\GroupbyIterator |
||
292 | * @deprecated Use group_by instead! |
||
293 | */ |
||
294 | public function deprecatedGroupBy($iterable, $strategy) |
||
298 | |||
299 | /** |
||
300 | * Make an iterator returning values from $iterable and keys from |
||
301 | * $strategy. |
||
302 | * |
||
303 | * @param array|string|\Iterator $iterable |
||
304 | * @param string|\Closure $strategy |
||
305 | * @return Itertools\lib\MapByIterator |
||
306 | * @deprecated Use map_by instead! |
||
307 | */ |
||
308 | public function deprecatedMapBy($iterable, $strategy) |
||
312 | |||
313 | /** |
||
314 | * Create a reduction |
||
315 | * |
||
316 | * @param array|string|\Iterator $iterable |
||
317 | * @param int $default |
||
318 | * @return int |
||
319 | * @deprecated Use reduce instead! |
||
320 | */ |
||
321 | public function deprecatedSum($iterable, $default = 0) |
||
328 | |||
329 | /** |
||
330 | * Takes an iterable and returns another iterable that is unique. |
||
331 | * |
||
332 | * @param array|string|\Iterator $iterable |
||
333 | * @param mixed $strategy |
||
334 | * @return Itertools\lib\UniqueIterator |
||
335 | * @deprecated Use unique instead! |
||
336 | */ |
||
337 | public function deprecatedUniqueBy($iterable, $strategy = null) |
||
341 | |||
342 | /** |
||
343 | * Returns a reduction closure |
||
344 | * |
||
345 | * @param string $name |
||
346 | * @return \Closure |
||
347 | * @throws \InvalidArgumentException |
||
348 | * @deprecated Use reducing instead! |
||
349 | */ |
||
350 | public function deprecatedGetReduction($name) |
||
354 | |||
355 | /** |
||
356 | * {@inheritDoc} |
||
357 | */ |
||
358 | 1 | public function getName() |
|
362 | } |
||
363 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.