Completed
Push — master ( 1857e6...d96bec )
by Joao
03:02
created

src/Repository/XmlDataset.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace ByJG\AnyDataset\Repository;
4
5
use ByJG\AnyDataset\Exception\DatasetException;
6
use ByJG\Util\XmlUtil;
7
use DOMDocument;
8
use InvalidArgumentException;
9
10
class XmlDataset
11
{
12
13
    /**
14
     * String
15
     *
16
     * @var string
17
     */
18
    private $_rowNode = null;
19
20
    /**
21
     * Enter description here...
22
     *
23
     * @var string[]
24
     */
25
    private $_colNodes = null;
26
27
    /**
28
     * @var DOMDocument
29
     */
30
    private $_domDocument;
31
32
    /**
33
     *
34
     * @var string
35
     */
36
    protected $_registerNS;
37
38
    /**
39
     *
40
     * @param DOMDocument $xml
41
     * @param string $rowNode
42
     * @param string[] $colNode
43
     * @param array $registerNS
44
     * @throws DatasetException
45
     * @throws InvalidArgumentException
46
     */
47
    public function __construct($xml, $rowNode, $colNode, $registerNS = null)
48
    {
49
        if (!is_array($colNode)) {
50
            throw new DatasetException("XmlDataset constructor: Column nodes must be an array.");
51
        }
52
53
        if ($xml instanceof DOMDocument) {
54
            $this->_domDocument = $xml;
55
        } else {
56
            $this->_domDocument = XmlUtil::createXmlDocumentFromStr($xml);
57
        }
58
59
        if (is_null($registerNS)) {
60
            $registerNS = array();
61
        }
62
63
        if (!is_array($registerNS)) {
64
            throw new InvalidArgumentException('The parameter $registerNS must be an associative array');
65
        }
66
67
        $this->_registerNS = $registerNS;
0 ignored issues
show
Documentation Bug introduced by
It seems like $registerNS of type array is incompatible with the declared type string of property $_registerNS.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
68
        $this->_rowNode = $rowNode;
69
        $this->_colNodes = $colNode;
70
    }
71
72
    /**
73
     * @access public
74
     * @return DBIterator
75
     */
76
    public function getIterator()
77
    {
78
        $it = new XmlIterator(XmlUtil::selectNodes($this->_domDocument->documentElement, $this->_rowNode,
79
                $this->_registerNS), $this->_colNodes, $this->_registerNS);
0 ignored issues
show
$this->_registerNS is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
        return $it;
81
    }
82
}
83