PAC::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
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