Completed
Push — master ( 9654f6...5e67fa )
by Roberto
14:40
created

Event   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 8.22 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 1
dl 6
loc 73
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D __callStatic() 6 31 9

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace NFePHP\eFinanc;
4
5
/**
6
 * Class eFinanc Event constructor
7
*
8
 * @category  API
9
 * @package   NFePHP\eFinanc
10
 * @copyright Copyright (c) 2018
11
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
12
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
13
 * @link      http://github.com/nfephp-org/sped-efinanceira for the canonical source repository
14
 */
15
use NFePHP\eFinanc\Exception\EventsException;
16
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
        'evtrerct' => Factories\EvtRERCT::class
33
    ];
34
    
35
    /**
36
     * Relationship between the code of the event and its respective name
37
     * @var array
38
     */
39
    private static $aliases = [
40
        'f1000' => 'evtaberturaefinanceira',
41
        'f2000' => 'evtcaddeclarante',
42
        'f2010' => 'evtcadintermediario',
43
        'f2020' => 'evtcadpatrocinado',
44
        'f3000' => 'evtmovopfin',
45
        'f4000' => 'evtfechamentoefinanceira',
46
        'f5000' => 'evtexclusao',
47
        'f8000' => 'evtrerct',
48
        'f9000' => 'evtexclusaoefinanceira'
49
    ];
50
    
51
    /**
52
     * Call classes to build XML EFDReinf Event
53
     * @param string $name
54
     * @param array $arguments [config, std, certificate, $date]
55
     * @return object
56
     * @throws NFePHP\eFinanc\Exception\EventsException
57
     */
58
    public static function __callStatic($name, $arguments)
59
    {
60
        $name = str_replace('-', '', strtolower($name));
61
        $realname = $name;
62
        if (substr($name, 0, 1) == 'f') {
63
            if (!array_key_exists($name, self::$aliases)) {
64
                //este evento não foi localizado
65
                throw EventsException::wrongArgument(1000, $name);
66
            }
67
            $realname = self::$aliases[$name];
68
        }
69
        if (!array_key_exists($realname, self::$available)) {
70
            //este evento não foi localizado
71
            throw EventsException::wrongArgument(1000, $name);
72
        }
73
        $className = self::$available[$realname];
74
        
75
        if (empty($arguments[0])) {
76
            throw EventsException::wrongArgument(1001);
77
        }
78
        if (empty($arguments[1])) {
79
            throw EventsException::wrongArgument(1002, $name);
80
        }
81 View Code Duplication
        if (count($arguments) > 2 && count($arguments) < 4) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
82
            return new $className($arguments[0], $arguments[1], $arguments[2]);
83
        }
84 View Code Duplication
        if (count($arguments) > 3) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
85
            return new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
86
        }
87
        return new $className($arguments[0], $arguments[1]);
88
    }
89
}
90