Completed
Push — master ( 431b60...331673 )
by Marko
10s
created

MaterialComponent::fog()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
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         MaterialComponent.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\Material;
25
26
use \AframeVR\Interfaces\Core\Components\MaterialCMPTIF;
27
use \AframeVR\Core\Helpers\ComponentAbstract;
28
use \AframeVR\Core\Exceptions\BadShaderCallException;
29
use \AframeVR\Interfaces\ShaderInterface;
30
31
class MaterialComponent extends ComponentAbstract implements MaterialCMPTIF
32
{
33
    private $shaderObj;
34
35
    /**
36
     * Initialize Component
37
     *
38
     * {@inheritdoc}
39
     *
40
     * @return bool
41
     */
42 40
    public function initializeComponent(): bool
43
    {
44 40
        $this->setDomAttribute('material');
45 40
        return true;
46
    }
47
48
    /**
49
     * Return DOM attribute contents
50
     *
51
     * @return string
52
     */
53 5
    public function getDomAttributeString(): string
54
    {
55 5
        $this->prepareShader();
56 5
        return parent::getDomAttributeString();
57
    }
58
59
    /**
60
     * Material Shader
61
     *
62
     * {@inheritdoc}
63
     *
64
     * @param null|string $shader            
65
     * @throws BadShaderCallException
66
     * @return object|null
67
     */
68 21
    public function shader(string $shader = null)
69
    {
70 21
        $this->dom_attributes['shader'] = $this->dom_attributes['shader'] ?? $shader ?? 'standard';
71
     
72 21
        if ($this->shaderObj instanceof ShaderInterface)
73 8
            return $this->shaderObj;
74
        
75 21
        $shader = sprintf('\AframeVR\Core\Shaders\%s', ucfirst($this->dom_attributes['shader']));
76 21
        if (class_exists($shader)) {
77 20
            $this->shaderObj = new $shader();
78
        } else {
79 1
            throw new BadShaderCallException($shader);
80
        }
81 20
        return $this->shaderObj ?? null;
82
    }
83
84
    /**
85
     * opacity
86
     *
87
     * {@inheritdoc}
88
     *
89
     * @param float $opacity            
90
     * @return MaterialCMPTIF
91
     */
92 11
    public function opacity(float $opacity = 1.0): MaterialCMPTIF
93
    {
94 11
        $this->dom_attributes['opacity'] = $opacity;
95 11
        return $this;
96
    }
97
98
    /**
99
     * transparent
100
     *
101
     * {@inheritdoc}
102
     *
103
     * @param bool $transparent            
104
     * @return MaterialCMPTIF
105
     */
106 12
    public function transparent(bool $transparent = false): MaterialCMPTIF
107
    {
108 12
        $this->dom_attributes['transparent'] = $transparent ? 'true' : 'false';
109 12
        return $this;
110
    }
111
112
    /**
113
     * depthTest
114
     *
115
     * {@inheritdoc}
116
     *
117
     * @param bool $depth_test            
118
     * @return MaterialCMPTIF
119
     */
120 1
    public function depthTest(bool $depth_test = true): MaterialCMPTIF
121
    {
122 1
        $this->dom_attributes['depthTest'] = $depth_test ? 'true' : 'false';
123 1
        return $this;
124
    }
125
126
    /**
127
     * side
128
     *
129
     * {@inheritdoc}
130
     *
131
     * @param string $side            
132
     * @return MaterialCMPTIF
133
     */
134 6
    public function side(string $side = 'front'): MaterialCMPTIF
135
    {
136 6
        $this->dom_attributes['side'] = $side;
137 6
        return $this;
138
    }
139
    
140
    /**
141
     * Do not apply fog to certain entities, we can disable fog for certain materials.
142
     *
143
     * @param string $side
0 ignored issues
show
Bug introduced by
There is no parameter named $side. 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...
144
     * @return MaterialCMPTIF
145
     */
146 1
    public function fog(bool $fog = true): MaterialCMPTIF
147
    {
148 1
        $this->dom_attributes['fog'] = $fog ? 'true' : 'false';;
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
149 1
        return $this;
150
    }
151
152
    /**
153
     * Prepare Shader attributes
154
     *
155
     * @return void
156
     */
157 5
    private function prepareShader()
158
    {
159 5
        if (! empty($this->shaderObj)) {
160 5
            $this->dom_attributes = array_merge($this->dom_attributes, $this->shaderObj->getAttributes());
161
        }
162 5
    }
163
}
164