Completed
Push — master ( 5c9909...94f348 )
by Marko
02:17
created

Primitives   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 5
dl 0
loc 123
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A box() 0 4 1
A camera() 0 4 1
A sphere() 0 4 1
A cylinder() 0 4 1
A plane() 0 4 1
A sky() 0 4 1
D DOMAppendPrimitives() 0 36 10
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 20, 2016 - 10:21:07 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         Primitives.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\Extras;
25
26
use \AframeVR\Extras\Primitives\{
27
    Sphere,
28
    Box,
29
    Cylinder,
30
    Plane,
31
    Sky
32
}
33
;
34
use \AframeVR\Core\Entity;
35
36
trait Primitives
37
{
38
39
    protected $spheres;
40
41
    protected $boxes;
42
43
    protected $cylinders;
44
45
    protected $planes;
46
47
    protected $sky;
48
49
    /**
50
     * A-Frame Primitive box
51
     *
52
     * @param string $name
53
     * @return Entity
54
     */
55
    public function box(string $name = 'untitled'): Entity
56
    {
57
        return $this->boxes[$name] ?? $this->boxes[$name] = new Box();
58
    }
59
    
60
    /**
61
     * A-Frame Primitive camera
62
     * 
63
     * @param string $name
64
     * @return Entity
65
     */
66
    public function camera(string $name = 'untitled'): Entity
67
    {
68
        return $this->cameras[$name] ?? $this->cameras[$name] = new Camera();
0 ignored issues
show
Bug introduced by
The property cameras does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
69
    }
70
    
71
    /**
72
     * A-Frame Primitive sphere
73
     *
74
     * @param string $name            
75
     * @return Entity
76
     */
77
    public function sphere(string $name = 'untitled'): Entity
78
    {
79
        return $this->spheres[$name] ?? $this->spheres[$name] = new Sphere();
80
    }
81
82
    
83
84
    /**
85
     * A-Frame Primitive cylinder
86
     *
87
     * @param string $name            
88
     * @return Entity
89
     */
90
    public function cylinder(string $name = 'untitled'): Entity
91
    {
92
        return $this->cylinders[$name] ?? $this->cylinders[$name] = new Cylinder();
93
    }
94
95
    /**
96
     * A-Frame Primitive plane
97
     *
98
     * @param string $name            
99
     * @return Entity
100
     */
101
    public function plane(string $name = 'untitled'): Entity
102
    {
103
        return $this->planes[$name] ?? $this->planes[$name] = new Plane();
104
    }
105
106
    /**
107
     * A-Frame Primitive sky
108
     *
109
     * @return Entity
110
     */
111
    public function sky(): Entity
112
    {
113
        return $this->sky = new Sky();
114
    }
115
116
    /**
117
     * Add all used primitevs to the scene
118
     *
119
     * @param \DOMDocument $aframe_dom            
120
     * @param \DOMElement $scene            
121
     */
122
    protected function DOMAppendPrimitives(\DOMDocument &$aframe_dom, \DOMElement &$scene)
123
    {
124
        /* Add sphiers to DOM */
125
        if (is_array($this->spheres)) {
126
            foreach ($this->spheres as $sphere) {
127
                $entity = $sphere->DOMElement($aframe_dom);
128
                $scene->appendChild($entity);
129
            }
130
        }
131
        /* Add boxes to DOM */
132
        if (is_array($this->boxes)) {
133
            foreach ($this->boxes as $box) {
134
                $entity = $box->DOMElement($aframe_dom);
135
                $scene->appendChild($entity);
136
            }
137
        }
138
        /* Add cylinders to DOM */
139
        if (is_array($this->cylinders)) {
140
            foreach ($this->cylinders as $cylinder) {
141
                $entity = $cylinder->DOMElement($aframe_dom);
142
                $scene->appendChild($entity);
143
            }
144
        }
145
        /* Add cylinders to DOM */
146
        if (is_array($this->planes)) {
147
            foreach ($this->planes as $plane) {
148
                $entity = $plane->DOMElement($aframe_dom);
149
                $scene->appendChild($entity);
150
            }
151
        }
152
        /* Add cylinders to DOM */
153
        if (is_object($this->sky)) {
154
            $entity = $this->sky->DOMElement($aframe_dom);
155
            $scene->appendChild($entity);
156
        }
157
    }
158
}
159