Completed
Push — master ( f8571a...f0770d )
by Marko
04:14
created

Primitives::DOMappendPrimitiveSky()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
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
use \AframeVR\Core\Entity;
34
35
trait Primitives
36
{
37
38
    /**
39
     *
40
     * @var array $spheres
41
     */
42
    protected $spheres = array();
43
44
    /**
45
     *
46
     * @var array $boxes
47
     */
48
    protected $boxes = array();
49
50
    /**
51
     *
52
     * @var array $cylinders
53
     */
54
    protected $cylinders = array();
55
56
    /**
57
     *
58
     * @var array $planes
59
     */
60
    protected $planes = array();
61
62
    /**
63
     *
64
     * @var \AframeVR\Extras\Primitives\Sky $sky
65
     */
66
    protected $sky;
67
68
    /**
69
     * A-Frame Primitive box
70
     *
71
     * @param string $name            
72
     * @return Entity
73
     */
74 9
    public function box(string $name = 'untitled'): Entity
75
    {
76 9
        return $this->boxes[$name] ?? $this->boxes[$name] = new Box();
77
    }
78
79
    /**
80
     * A-Frame Primitive sphere
81
     *
82
     * @param string $name            
83
     * @return Entity
84
     */
85 5
    public function sphere(string $name = 'untitled'): Entity
86
    {
87 5
        return $this->spheres[$name] ?? $this->spheres[$name] = new Sphere();
88
    }
89
90
    /**
91
     * A-Frame Primitive cylinder
92
     *
93
     * @param string $name            
94
     * @return Entity
95
     */
96 5
    public function cylinder(string $name = 'untitled'): Entity
97
    {
98 5
        return $this->cylinders[$name] ?? $this->cylinders[$name] = new Cylinder();
99
    }
100
101
    /**
102
     * A-Frame Primitive plane
103
     *
104
     * @param string $name            
105
     * @return Entity
106
     */
107 5
    public function plane(string $name = 'untitled'): Entity
108
    {
109 5
        return $this->planes[$name] ?? $this->planes[$name] = new Plane();
110
    }
111
112
    /**
113
     * A-Frame Primitive sky
114
     *
115
     * @return Entity
116
     */
117 5
    public function sky(): Entity
118
    {
119 5
        return $this->sky = new Sky();
120
    }
121
122
    /**
123
     * Add all used primitevs to the scene
124
     *
125
     * @param \DOMDocument $aframe_dom            
0 ignored issues
show
Bug introduced by
There is no parameter named $aframe_dom. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
126
     * @param \DOMElement $scene            
0 ignored issues
show
Bug introduced by
There is no parameter named $scene. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
127
     * @return void
128
     */
129 3
    protected function preparePrimitives()
130
    {
131
        /* Primitive collections */
132 3
        $this->aframeDomObj->appendEntities($this->boxes);
0 ignored issues
show
Bug introduced by
The property aframeDomObj 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...
133 3
        $this->aframeDomObj->appendEntities($this->spheres);
134 3
        $this->aframeDomObj->appendEntities($this->cylinders);
135 3
        $this->aframeDomObj->appendEntities($this->planes);
136
        
137
        /* Primitives which only one can be present */
138 3
        (!$this->sky)?:$this->aframeDomObj->appendEntity($this->sky);
139 3
    }
140
}
141