PAC   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 9.09 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 7
loc 77
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A __call() 0 21 3

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
/*
4
 * This file is part of the cfdi-certificate project.
5
 *
6
 * (c) Kinedu
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Kinedu\CfdiPac;
13
14
use Exception;
15
16
class PAC
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $pacs = [
22
        'InvoiceOne' => \Kinedu\CfdiPac\Strategies\InvoiceOneStrategy::class,
23
    ];
24
25
    /**
26
     * Client username.
27
     *
28
     * @var string
29
     */
30
    protected $username;
31
32
    /**
33
     * Client password.
34
     *
35
     * @var string
36
     */
37
    protected $password;
38
39
    /**
40
     * CFDI XML.
41
     *
42
     * @var string
43
     */
44
    protected $xml;
45
46
    /**
47
     * @var bool
48
     */
49
    protected $test;
50
51
    /**
52
     * Create a new pac instance.
53
     *
54
     * @param  string  $username
55
     * @param  string  $password
56
     * @param  string  $xml
57
     * @param  bool  $test
58
     */
59 View Code Duplication
    public function __construct(string $username, string $password, string $xml, bool $test = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
60
    {
61
        $this->username = $username;
62
        $this->password = $password;
63
        $this->xml = $xml;
64
        $this->test = $test;
65
    }
66
67
    /**
68
     * @param  string  $method
69
     * @param  string  $arguments
70
     */
71
    public function __call(string $method, array $arguments)
72
    {
73
        $prefix = 'use';
74
75
        if ((substr($method, 0, 3) === $prefix)) {
76
            $name = substr($method, strlen($prefix));
77
78
            if ($pac = $this->pacs[$name]) {
79
                $p = new $pac(
80
                    $this->username,
81
                    $this->password,
82
                    $this->xml,
83
                    $this->test
84
                );
85
86
                return $p;
87
            } else {
88
                throw new Exception("This method doesn't exist");
89
            }
90
        }
91
    }
92
}
93