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 |
||
8 | class LangFilter implements FilterInterface |
||
9 | { |
||
10 | protected $langGenerator; |
||
11 | |||
12 | 20 | public function __construct(Translator $langGenerator) |
|
13 | { |
||
14 | 20 | $this->langGenerator = $langGenerator; |
|
15 | 20 | } |
|
16 | |||
17 | 19 | public function transform($item, Builder $builder) |
|
18 | { |
||
19 | 19 | if (isset($item['header'])) { |
|
20 | 2 | $item['header'] = ($this->langGenerator->has('adminlte::menu.'.$item['header'])) ? $this->langGenerator->get('adminlte::menu.'.$item['header'])) : $item['header']; |
|
|
|||
21 | } |
||
22 | 19 | if (isset($item['text'])) { |
|
23 | 17 | $item['text'] = ($this->langGenerator->has('adminlte::menu.'.$item['text'])) ? $this->langGenerator->get('adminlte::menu.'.$item['text']) : $tem['text']; |
|
24 | } |
||
25 | |||
26 | 19 | return $item; |
|
27 | } |
||
28 | } |
||
29 |