Event::__callStatic()   C
last analyzed

Complexity

Conditions 12
Paths 15

Size

Total Lines 34

Duplication

Lines 6
Ratio 17.65 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 6
loc 34
rs 6.9666
cc 12
nc 15
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        '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)
63
    {
64
        $name = str_replace('-', '', strtolower($name));
65
        $realname = $name;
66
        if (substr($name, 0, 1) == 'f') {
67
            if (!array_key_exists($name, self::$aliases)) {
68
                //este evento não foi localizado
69
                throw EventsException::wrongArgument(1000, $name);
70
            }
71
            $realname = self::$aliases[$name];
72
        }
73
        if (!array_key_exists($realname, self::$available)) {
74
            //este evento não foi localizado
75
            throw EventsException::wrongArgument(1000, $name);
76
        }
77
        $className = self::$available[$realname];
78
        
79
        if (empty($arguments[0])) {
80
            throw EventsException::wrongArgument(1001);
81
        }
82
        if (empty($arguments[1])) {
83
            throw EventsException::wrongArgument(1002, $name);
84
        }
85
        if (count($arguments) > 2 && count($arguments) < 4) {
86
            return new $className($arguments[0], $arguments[1], $arguments[2]);
87
        }
88 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...
89
            return new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
90
        }
91 View Code Duplication
        if (count($arguments) > 4 && count($arguments) < 6) {
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...
92
            return new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]);
93
        }
94
        return new $className($arguments[0], $arguments[1]);
95
    }
96
}
97