Completed
Push — master ( 8ed914...095f85 )
by Roberto
25:48 queued 11:05
created

Event   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 7.69 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
C __callStatic() 6 34 12

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
        'evtmovopfinanual' => Factories\EvtMovOpFinAnual::class,
33
        'evtrerct' => Factories\EvtRERCT::class
34
    ];
35
    
36
    /**
37
     * Relationship between the code of the event and its respective name
38
     * @var array
39
     */
40
    private static $aliases = [
41
        'f1000' => 'evtaberturaefinanceira',
42
        'f2000' => 'evtcaddeclarante',
43
        'f2010' => 'evtcadintermediario',
44
        'f2020' => 'evtcadpatrocinado',
45
        'f3000' => 'evtmovopfin',
46
        'f3010' => 'evtmovopfinanual',
47
        'f4000' => 'evtfechamentoefinanceira',
48
        'f5000' => 'evtexclusao',
49
        'f8000' => 'evtrerct',
50
        'f9000' => 'evtexclusaoefinanceira'
51
    ];
52
    
53
    /**
54
     * Call classes to build XML EFDReinf Event
55
     * @param string $name
56
     * @param array $arguments [config, std, certificate, $date]
57
     * @return object
58
     * @throws NFePHP\eFinanc\Exception\EventsException
59
     */
60
    public static function __callStatic($name, $arguments)
61
    {
62
        $name = str_replace('-', '', strtolower($name));
63
        $realname = $name;
64
        if (substr($name, 0, 1) == 'f') {
65
            if (!array_key_exists($name, self::$aliases)) {
66
                //este evento não foi localizado
67
                throw EventsException::wrongArgument(1000, $name);
68
            }
69
            $realname = self::$aliases[$name];
70
        }
71
        if (!array_key_exists($realname, self::$available)) {
72
            //este evento não foi localizado
73
            throw EventsException::wrongArgument(1000, $name);
74
        }
75
        $className = self::$available[$realname];
76
        
77
        if (empty($arguments[0])) {
78
            throw EventsException::wrongArgument(1001);
79
        }
80
        if (empty($arguments[1])) {
81
            throw EventsException::wrongArgument(1002, $name);
82
        }
83 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...
84
            return new $className($arguments[0], $arguments[1], $arguments[2]);
85
        }
86 View Code Duplication
        if (count($arguments) > 3 && count($arguments) < 5) {
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...
87
            return new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
88
        }
89
        if (count($arguments) > 4 && count($arguments) < 6) {
90
            return new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]);
91
        }
92
        return new $className($arguments[0], $arguments[1]);
93
    }
94
}
95