Completed
Push — master ( e254bb...d44235 )
by Marko
02:18
created

GeometryComponent::getDomAttributeString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 25, 2016 - 7:51:42 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         GeometryComponent.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\Components\Geometry;
25
26
use \AframeVR\Core\Helpers\ComponentAbstract;
27
use \AframeVR\Interfaces\Core\Components\Geometry\GeometryInterface;
28
use \AframeVR\Core\Exceptions\InvalidComponentArgumentException;
29
30
/**
31
 * AframeVR\Core\Components\Geometry
32
 *
33
 * The geometry component provides a basic shape for an entity.
34
 * The general geometry is defined by the primitive property.
35
 * Geometric primitives, in computer graphics, means an extremely
36
 * basic shape. With the primitive defined, additional properties
37
 * are used to further define the geometry. A material component
38
 * is usually defined alongside to provide a appearance
39
 * alongside the shape to create a complete mesh.
40
 */
41
class GeometryComponent extends ComponentAbstract implements GeometryInterface
42
{
43
44
    /**
45
     * Initialize Component
46
     *
47
     * {@inheritdoc}
48
     *
49
     * @return bool
50
     */
51 40
    public function initializeComponent(): bool
52
    {
53 40
        $this->setDomAttributeName('geometry');
54 40
        return true;
55
    }
56
    
57
    /**
58
     * Set geometry primitive
59
     *
60
     * One of box, circle, cone, cylinder, plane, ring, sphere, torus, torusKnot.
61
     *
62
     * @param string $primitive            
63
     * @throws InvalidComponentArgumentException
64
     * @return void
65
     */
66 38
    public function primitive(string $primitive)
67
    {
68 38
        if (in_array($primitive, self::ALLOWED_PRIMITIVES)) {     
69 37
            $this->dom_attributes              = array();
70 37
            $method_provider                   = sprintf('%sMethods', ucfirst($primitive));
71 37
            $this->dom_attributes['primitive'] = $primitive;
72
            
73 37
            $this->setMethodProvider($method_provider);
74
        } else {
75 2
            throw new InvalidComponentArgumentException((string) $primitive, 'Geometry::primitive');
76
        }
77 37
    }
78
79
    /**
80
     * translate
81
     *
82
     * {@inheritdoc}
83
     *
84
     * @param int|float $x            
85
     * @param int|float $y            
86
     * @param int|float $z            
87
     * @return void
88
     */
89 7
    public function translate(float $x = 0, float $y = 0, float $z = 0)
90
    {
91 7
        $this->dom_attributes['translate'] = sprintf('%d %d %d', $x, $y, $z);
92 7
    }
93
94
    /**
95
     * Set Buffer
96
     *
97
     * {@inheritdoc}
98
     *
99
     * @param bool $buffer            
100
     * @return void
101
     */
102 1
    public function buffer(bool $buffer = true)
103
    {
104 1
        $this->dom_attributes['buffer'] = $buffer ? 'true' : 'false';
105 1
    }
106
107
    /**
108
     * skipCache
109
     *
110
     * {@inheritdoc}
111
     *
112
     * @param bool $skipCache            
113
     * @return void
114
     */
115 1
    public function skipCache(bool $skipCache = false)
116
    {
117 1
        $this->dom_attributes['skipCache'] = $skipCache ? 'true' : 'false';
118 1
    }
119
}
120