XPath::getXPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\CAS\Utils;
6
7
use DOMNode;
8
use DOMXPath;
9
use SimpleSAML\CAS\Constants as C;
10
11
/**
12
 * Compilation of utilities for XPath.
13
 *
14
 * @package simplesamlphp/cas
15
 */
16
class XPath extends \SimpleSAML\XPath\XPath
17
{
18
    /**
19
     * Get a DOMXPath object that can be used to search for CAS elements.
20
     *
21
     * @param \DOMNode $node The document to associate to the DOMXPath object.
22
     * @param bool $autoregister Whether to auto-register all namespaces used in the document
23
     *
24
     * @return \DOMXPath A DOMXPath object ready to use in the given document, with several
25
     *   cas-related namespaces already registered.
26
     */
27
    public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath
28
    {
29
        $xp = parent::getXPath($node, $autoregister);
30
31
        /*
32
         * - Registering 'cas' to the same URI again is fine.
33
         * - If someone previously bound 'cas' to a different URI on the same DOMXPath,
34
         *   your call will change its meaning for subsequent queries
35
         * */
36
        $xp->registerNamespace('cas', C::NS_CAS);
37
38
        return $xp;
39
    }
40
}
41