DomTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createDom() 0 8 1
A createXmlDom() 0 11 2
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDev/ for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2019 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDev\Test;
11
12
use DOMDocument;
13
use DOMXPath;
14
15
/**
16
 * WebDriver test DOM trait
17
 *
18
 * Use this trait when you want DOM testing.
19
 */
20
trait DomTrait
21
{
22
    /**
23
     * Create DOM document from XHTML source
24
     *
25
     * @param string $xhtml
26
     * @return DOMDocument
27
     */
28
    public function createDom($xhtml)
29
    {
30
        $dom = new DOMDocument;
31
        libxml_use_internal_errors(true);
32
        $dom->loadHTML($xhtml);
33
        $dom->xpath = new DOMXPath($dom);
34
        return $dom;
35
    }
36
37
    /**
38
     * Create DOM document from XML source
39
     *
40
     * @param string $xml
41
     * @param null $namespace
42
     * @return DOMDocument
43
     */
44
    public function createXmlDom($xml, $namespace = null)
45
    {
46
        $dom = new DOMDocument;
47
        $dom->loadXML($xml);
48
        $dom->xpath = new DOMXPath($dom);
49
50
        $namespace
51
            and $dom->xpath->registerNamespace($namespace, $dom->lookupNamespaceUri($dom->namespaceURI));
52
53
        return $dom;
54
    }
55
}
56