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 |
||
17 | class Event |
||
18 | { |
||
19 | /** |
||
20 | * Relationship between the name of the event and its respective class |
||
21 | * @var array |
||
22 | */ |
||
23 | private static $available = [ |
||
24 | 'evtaberturaefinanceira' => Factories\EvtAberturaeFinanceira::class, |
||
25 | 'evtcaddeclarante' => Factories\EvtCadDeclarante::class, |
||
26 | 'evtcadintermediario' => Factories\EvtCadIntermediario::class, |
||
27 | 'evtcadpatrocinado' => Factories\EvtCadPatrocinado::class, |
||
28 | 'evtexclusao' => Factories\EvtExclusao::class, |
||
29 | 'evtexclusaoefinanceira' => Factories\EvtExclusaoeFinanceira::class, |
||
30 | 'evtfechamentoefinanceira' => Factories\EvtFechamentoeFinanceira::class, |
||
31 | 'evtmovopfin' => Factories\EvtMovOpFin::class, |
||
32 | 'evtmovpp' => Factories\EvtMovPP::class, |
||
33 | 'evtmovopfinanual' => Factories\EvtMovOpFinAnual::class, |
||
34 | 'evtrerct' => Factories\EvtRERCT::class |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * Relationship between the code of the event and its respective name |
||
39 | * @var array |
||
40 | */ |
||
41 | private static $aliases = [ |
||
42 | 'f1000' => 'evtaberturaefinanceira', |
||
43 | 'f2000' => 'evtcaddeclarante', |
||
44 | 'f2010' => 'evtcadintermediario', |
||
45 | 'f2020' => 'evtcadpatrocinado', |
||
46 | 'f3000' => 'evtmovopfin', |
||
47 | 'f3010' => 'evtmovopfinanual', |
||
48 | 'f4000' => 'evtfechamentoefinanceira', |
||
49 | 'f5000' => 'evtexclusao', |
||
50 | 'f6000' => 'evtmovpp', |
||
51 | 'f8000' => 'evtrerct', |
||
52 | 'f9000' => 'evtexclusaoefinanceira' |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * Call classes to build XML EFDReinf Event |
||
57 | * @param string $name |
||
58 | * @param array $arguments [config, std, certificate, $date] |
||
59 | * @return object |
||
60 | * @throws NFePHP\eFinanc\Exception\EventsException |
||
61 | */ |
||
62 | public static function __callStatic($name, $arguments) |
||
96 | } |
||
97 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.