Completed
Push — master ( ad5651...3fe817 )
by Marko
02:53
created

AssetsAbstract::domElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 28, 2016 - 3:47:35 PM
5
 * Contact      [email protected]
6
 * @copyright   2016 Marko Kungla - https://github.com/mkungla
7
 * @license     The MIT License (MIT)
8
 * 
9
 * @category       AframeVR
10
 * @package        aframe-php
11
 * 
12
 * Lang         PHP (php version >= 7)
13
 * Encoding     UTF-8
14
 * File         AssetsAbstract.php
15
 * Code format  PSR-2 and 12
16
 * @link        https://github.com/mkungla/aframe-php
17
 ^ @issues      https://github.com/mkungla/aframe-php/issues
18
 * ********************************************************************
19
 * Contributors:
20
 * @author Marko Kungla <[email protected]>
21
 * ********************************************************************
22
 * Comments:
23
 * @formatter:on */
24
namespace AframeVR\Core\Helpers;
25
26
use \AframeVR\Interfaces\AssetsInterface;
27
use \DOMElement;
28
29
abstract class AssetsAbstract implements AssetsInterface
30
{
31
32
    /**
33
     * DOM tag name of asset item
34
     *
35
     * @var string $element_name
36
     */
37
    protected $element_name = 'a-asset-item';
38
39
    /**
40
     * ID attribute
41
     *
42
     * @var string
43
     */
44
    protected $attr_id;
45
46
    /**
47
     * SRC attribute
48
     *
49
     * @var string
50
     */
51
    protected $attr_src;
52
53
    /**
54
     * Asset constructor set asset ID
55
     *
56
     * @param string $id            
57
     */
58 5
    public function __construct(string $id)
59
    {
60 5
        $this->id($id);
61 5
    }
62
63
    /**
64
     * Set ID attribute of the asset
65
     *
66
     * {@inheritdoc}
67
     *
68
     * @param string $id            
69
     */
70 5
    public function id(string $id = 'untitled')
71
    {
72 5
        $this->attr_id = $id;
73 5
    }
74
75
    /**
76
     * Set Assets src attribute
77
     *
78
     * {@inheritdoc}
79
     *
80
     * @param null|string $src            
81
     * @return void
82
     */
83 3
    public function src(string $src = null)
84
    {
85 3
        $this->attr_src = $src;
86 3
    }
87
88
    /**
89
     * Create and add DOM element of the asset
90
     *
91
     * @param \DOMDocument $aframe_dom            
92
     * @return \DOMElement
93
     */
94 2
    public function domElement(&$aframe_dom): DOMElement
95
    {
96 2
        $a_asset = $aframe_dom->createElement($this->element_name);
97 2
        $a_asset->setAttribute('id', $this->attr_id);
98 2
        return $a_asset;
99
    }
100
}
101