Completed
Branch master (fb685e)
by Marko
02:00
created

Component::shader()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
crap 3
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         PositionComponent.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\Core\Helpers\ComponentAbstract;
27
use \AframeVR\Interfaces\ComponentInterface;
28
use \AframeVR\Interfaces\Core\Components\Material\MaterialInterface;
29
use \AframeVR\Core\Exceptions\BadShaderCallException;
30
use \AframeVR\Interfaces\ShaderInterface;
31
32
class Component extends ComponentAbstract implements ComponentInterface, MaterialInterface
33
{
34
35
    private $shaderObj;
36
37
    /**
38
     * Initialize Component
39
     *
40
     * {@inheritdoc}
41
     *
42
     * @return bool
43
     */
44 32
    public function initializeComponent(): bool
45
    {
46 32
        $this->setDomAttributeName('material');
47 32
        return true;
48
    }
49
50
    /**
51
     * Return DOM attribute contents
52
     *
53
     * @return string
54
     */
55 1
    public function getDomAttributeString(): string
56
    {
57 1
        $attrs = $this->getDOMAttributesArray();
0 ignored issues
show
Unused Code introduced by
$attrs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58 1
        return '';
59
    }
60
61
    /**
62
     * Material Shader
63
     *
64
     * {@inheritdoc}
65
     *
66
     * @param string $shader            
67
     * @throws BadShaderCallException
68
     * @return object|null
69
     */
70 12
    public function shader(string $shader = 'standard')
71
    {
72 12
        if ($this->shaderObj instanceof ShaderInterface)
73 2
            return $this->shaderObj;
74
        
75 12
        $shader = sprintf('\AframeVR\Core\Shaders\%s', ucfirst($shader));
76 12
        if (class_exists($shader)) {
77 11
            $this->shaderObj = new $shader();
78
        } else {
79 1
            throw new BadShaderCallException($shader);
80
        }
81 11
        return $this->shaderObj ?? null;
82
    }
83
}
84