Completed
Push — master ( ef63c8...ac3086 )
by Derek Stephen
03:11
created

HasDomTrait::setDom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * User: delboy1978uk
4
 * Date: 27/12/2016
5
 * Time: 00:27
6
 */
7
8
namespace Del\Form\Traits;
9
10
use DOMDocument;
11
use DOMElement;
12
use DOMText;
13
14
trait HasDomTrait
15
{
16
    /** @var DOMDocument $dom  */
17
    private $dom;
18
19
    /**
20
     * @param $tagType
21
     * @return DOMElement
22
     */
23 21
    public function createElement($tagType)
24
    {
25 21
        return $this->dom->createElement($tagType);
26
    }
27
28
    /**
29
     * @param $text
30
     * @return DOMText
31
     */
32 15
    public function createText($text)
33
    {
34 15
        return new DOMText($text);
35
    }
36
37
    /**
38
     * @return DOMElement
39
     */
40 2
    public function createLineBreak()
41
    {
42 2
        return $this->createElement('br');
43
    }
44
45
    /**
46
     * @return DOMDocument
47
     */
48 40
    public function getDom()
49
    {
50 40
        return $this->dom;
51
    }
52
53
    /**
54
     * @param DOMDocument $dom
55
     * @return HasDomTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type HasDomTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
56
     */
57 40
    public function setDom($dom)
58
    {
59 40
        $this->dom = $dom;
60 40
        return $this;
61
    }
62
}