PACSoapRequest::getXML()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
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 DOMDocument;
15
16
abstract class PACSoapRequest
17
{
18
    /**
19
     * Client username.
20
     *
21
     * @var string
22
     */
23
    protected $username;
24
25
    /**
26
     * Client password.
27
     *
28
     * @var string
29
     */
30
    protected $password;
31
32
    /**
33
     * CFDI XML.
34
     *
35
     * @var string
36
     */
37
    protected $xml;
38
39
    /**
40
     * @param bool
41
     */
42
    protected $test;
43
44
    /** @var array */
45
    protected $options = [
46
        'soap_version' => SOAP_1_2,
47
        'trace' => 1,
48
    ];
49
50
    /**
51
     * Create a new invoice one strategy instance.
52
     *
53
     * @param  string  $username
54
     * @param  string  $password
55
     * @param  string  $xml
56
     * @param  bool  $test
57
     */
58 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...
59
    {
60
        $this->username = $username;
61
        $this->password = $password;
62
        $this->xml = $xml;
63
        $this->test = $test;
64
65
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
66
    }
67
68
    /**
69
     * Soap request.
70
     *
71
     * @return mixed
72
     */
73
    abstract protected function makeRequest();
74
75
    /**
76
     * Returns the cfdi with the TFD node.
77
     *
78
     * @return string
79
     */
80
    abstract public function getXML();
81
82
    /**
83
     * @param string $filename
84
     *
85
     * @return integer
86
     */
87
    public function save(string $filename)
88
    {
89
        $xml = new DOMDocument();
90
        $xml->preserveWhiteSpace = true;
91
        $xml->formatOutput = true;
92
        $xml->loadXML($this->getXML());
93
94
        return $xml->save($filename);
95
    }
96
}
97