Completed
Push — master ( e8b22d...bec3f6 )
by Marko
11s
created

Mixin::metalness()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 20, 2016 - 9:12:11 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         Mixin.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\Assets;
25
26
use \AframeVR\Core\Exceptions\BadComponentCallException;
27
use \AframeVR\Interfaces\Core\Assets\MixinInterface;
28
use \AframeVR\Core\Helpers\AssetsAbstract;
29
use \Closure;
30
31
final class Mixin extends AssetsAbstract implements MixinInterface
32
{
33
34
    /**
35
     * DOM tag name of asset item
36
     *
37
     * @var string
38
     */
39
    protected $element_tag = 'a-mixin';
40
    
41
    /**
42
     * Array of mocked components
43
     *
44
     * @var array
45
     */
46
    protected $components = array();
47
48
    /**
49
     * Load component for this entity
50
     *
51
     * @param string $component_name            
52
     * @throws \AframeVR\Core\Exceptions\BadComponentCallException
53
     * @return object|null
54
     */
55 2 View Code Duplication
    public function component(string $component_name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57 2
        if (! array_key_exists($component_name, $this->components)) {
58 2
            $component = sprintf('\AframeVR\Core\Components\%s\%sComponent', ucfirst($component_name), 
59
                ucfirst($component_name));
60 2
            if (class_exists($component)) {
61 1
                $this->components[$component_name] = new $component();
62
            } else {
63 1
                throw new BadComponentCallException($component_name);
64
            }
65
        }
66
        
67 1
        return $this->components[$component_name] ?? null;
68
    }
69
    
70
    /**
71
     * Handle entity components
72
     *
73
     * Since we might need to customize these to have
74
     * custom components loaded as $this->methosd aswell therefore
75
     * we have these placeholder magic methods here
76
     *
77
     * @param string $component_name            
78
     * @param array $args            
79
     */
80 1 View Code Duplication
    public function __call(string $component_name, array $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82 1
        if (! method_exists($this, $component_name)) {
83 1
            $this->{$component_name} = Closure::bind(
84 1
                function () use ($component_name) {
85 1
                    return $this->component($component_name);
86 1
                }, $this, get_class());
87
        }
88
        
89 1
        return call_user_func($this->{$component_name}, $args);
90
    }
91
    
92
    /**
93
     * material.color
94
     *
95
     * @param string $color
96
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
97
     */
98 1
    public function color(string $color = 'gray')
99
    {
100 1
        $this->component('Material')
101 1
        ->shader()
102 1
        ->color($color);
103 1
        return $this;
104
    }
105
    
106
    /**
107
     * material.metalness
108
     *
109
     * @param int|float $metalness
110
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
111
     */
112 1
    public function metalness(float $metalness = 0)
113
    {
114 1
        $this->component('Material')
115 1
        ->shader()
116 1
        ->metalness($metalness);
117 1
        return $this;
118
    }
119
    
120
    /**
121
     * material.roughness
122
     *
123
     * @param float $roughness
124
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
125
     */
126 1
    public function roughness(float $roughness = 0.5)
127
    {
128 1
        $this->component('Material')
129 1
        ->shader()
130 1
        ->roughness($roughness);
131 1
        return $this;
132
    }
133
    
134
    /**
135
     * material.src
136
     *
137
     * @param null|string $src
138
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
139
     */
140 1
    public function src(string $src = null)
141
    {
142 1
        $this->component('Material')
143 1
        ->shader()
144 1
        ->src($src);
145 1
        return $this;
146
    }
147
    
148
    /**
149
     * geometry.translate
150
     *
151
     * @param int|float $x
152
     * @param int|float $y
153
     * @param int|float $z
154
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
155
     */
156 1
    public function translate(float $x = 0, float $y = 0, float $z = 0)
157
    {
158 1
        $this->component('Geometry')->translate($x, $y, $z);
159 1
        return $this;
160
    }
161
    
162
    /**
163
     * material.shader
164
     *
165
     * @param string $shader
166
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
167
     */
168 1
    public function shader($shader = 'standard')
169
    {
170 1
        $this->component('Material')->shader($shader);
171 1
        return $this;
172
    }
173
    
174
    /**
175
     * material.opacity
176
     *
177
     * @param float $opacity
178
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
179
     */
180 1
    public function opacity(float $opacity = 1.0)
181
    {
182 1
        $this->component('Material')->opacity($opacity);
183 1
        return $this;
184
    }
185
    
186
    /**
187
     * material.transparent
188
     *
189
     * @param bool $transparent
190
     * @return EntityInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be Mixin?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
191
     */
192 1
    public function transparent(bool $transparent = false)
193
    {
194 1
        $this->component('Material')->transparent($transparent);
195 1
        return $this;
196
    }
197
}
198