Completed
Push — master ( 697c38...fae26d )
by Marko
9s
created

SoundComponent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 86
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeComponent() 0 5 1
A autoplay() 0 5 2
A on() 0 5 1
A loop() 0 5 2
A src() 0 5 1
A volume() 0 5 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jul 6, 2016 - 9:38:05 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         SoundComponent.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\Sound;
25
26
use \AframeVR\Interfaces\Core\Components\SoundCMPTIF;
27
use \AframeVR\Core\Helpers\ComponentAbstract;
28
29
class SoundComponent extends ComponentAbstract implements SoundCMPTIF
30
{
31
32
    /**
33
     * Initialize Component
34
     *
35
     * {@inheritdoc}
36
     *
37
     * @return bool
38
     */
39 6
    public function initializeComponent(): bool
40
    {
41 6
        $this->setDomAttribute('sound');
42 6
        return true;
43
    }
44
45
    /**
46
     * Autoplay sound
47
     *
48
     * Whether to automatically play sound once set.
49
     *
50
     * @param bool $autoplay            
51
     * @return SoundCMPTIF
52
     */
53 5
    public function autoplay(bool $autoplay = false): SoundCMPTIF
54
    {
55 5
        $this->dom_attributes['autoplay'] = $autoplay ? 'true' : 'false';
56 5
        return $this;
57
    }
58
59
    /**
60
     * Play event
61
     *
62
     * An event for the entity to listen to before playing sound.
63
     *
64
     * @param string $event            
65
     * @return SoundCMPTIF
66
     */
67 1
    public function on(string $event = 'click'): SoundCMPTIF
68
    {
69 1
        $this->dom_attributes['on'] = $event;
70 1
        return $this;
71
    }
72
73
    /**
74
     * Loop sound
75
     *
76
     * Whether to loop the sound once the sound finishes playing.
77
     *
78
     * @param bool $loop            
79
     * @return SoundCMPTIF
80
     */
81 1
    public function loop(bool $loop = false): SoundCMPTIF
82
    {
83 1
        $this->dom_attributes['loop'] = $loop ? 'true' : 'false';
84 1
        return $this;
85
    }
86
87
    /**
88
     * Audio source
89
     *
90
     * Path to sound file.
91
     *
92
     * @param null|string $src            
93
     * @return SoundCMPTIF
94
     */
95 4
    public function src(string $src = null): SoundCMPTIF
96
    {
97 4
        $this->dom_attributes['src'] = $src;
98 4
        return $this;
99
    }
100
101
    /**
102
     * Volume
103
     *
104
     * How loud to play the sound.
105
     *
106
     * @param int|float $vol            
107
     * @return SoundCMPTIF
108
     */
109 1
    public function volume(float $vol = 1): SoundCMPTIF
110
    {
111 1
        $this->dom_attributes['volume'] = $vol;
112 1
        return $this;
113
    }
114
}