Completed
Branch 0.3.x (efbbbe)
by Marko
02:32
created

Assets::img()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jun 20, 2016 - 9:08:14 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         Assets.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;
25
26
use \AframeVR\Interfaces\Core\Assets\{
27
    AssetAudioInterface,
28
    AssetImageInterface,
29
    AssetItemInterface,
30
    AssetVideoInterface,
31
    MixinInterface
32
};
33
use \AframeVR\Core\Assets\{
34
    AssetAudio,
35
    AssetImage,
36
    AssetItem,
37
    AssetVideo,
38
    Mixin
39
};
40
41
final class Assets
42
{
43
44
    /**
45
     * Array of mixins
46
     *
47
     * @var array
48
     */
49
    protected $assets;
50
51
    /**
52
     * <a-scene><a-assets><audio>
53
     *
54
     * @param string $id            
55
     * @return \AframeVR\Interfaces\Core\Assets\ItemInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be \AframeVR\Interfaces\Cor...ets\AssetAudioInterface?

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...
56
     */
57 4
    public function audio(string $id = 'untitled'): AssetAudioInterface
58
    {
59 4
        return $this->assets[$id] ?? $this->assets[$id] = new AssetAudio($id);
60
    }
61
62
    /**
63
     * <a-scene><a-assets><img>
64
     *
65
     * @param string $id            
66
     * @return \AframeVR\Interfaces\Core\Assets\ItemInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be \AframeVR\Interfaces\Cor...ets\AssetImageInterface?

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...
67
     */
68 4
    public function img(string $id = 'untitled'): AssetImageInterface
69
    {
70 4
        return $this->assets[$id] ?? $this->assets[$id] = new AssetImage($id);
71
    }
72
73
    /**
74
     * <a-scene><a-assets><a-asset-item>
75
     *
76
     * @param string $id            
77
     * @return \AframeVR\Interfaces\Core\Assets\ItemInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be \AframeVR\Interfaces\Cor...sets\AssetItemInterface?

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...
78
     */
79 4
    public function item(string $id = 'untitled'): AssetItemInterface
80
    {
81 4
        return $this->assets[$id] ?? $this->assets[$id] = new AssetItem($id);
82
    }
83
84
    /**
85
     * <a-scene><a-assets><video>
86
     *
87
     * @param string $id            
88
     * @return \AframeVR\Interfaces\Core\Assets\ItemInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be \AframeVR\Interfaces\Cor...ets\AssetVideoInterface?

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...
89
     */
90 1
    public function video(string $id = 'untitled'): AssetVideoInterface
91
    {
92 1
        return $this->assets[$id] ?? $this->assets[$id] = new AssetVideo($id);
93
    }
94
95
    /**
96
     * Mixin which will be directly applied to element usin it
97
     *
98
     * A-Frame PHP does not create <a-mixin>. Instead it is appling
99
     * mixin directly on element using this mixin.
100
     *
101
     * @param string $id            
102
     * @return \AframeVR\Interfaces\Core\Assets\MixinInterface
103
     */
104 5
    public function mixin(string $id = 'untitled'): MixinInterface
105
    {
106 5
        return $this->assets[$id] ?? $this->assets[$id] = new Mixin($id);
107
    }
108
109
    /**
110
     * Setting a timeout
111
     *
112
     * @param int $milliseconds            
113
     * @return Assets;
0 ignored issues
show
Documentation introduced by
The doc-type Assets; could not be parsed: Expected "|" or "end of type", but got ";" at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
114
     */
115 1
    public function timeout(int $milliseconds = 3000)
116
    {
117 1
        $this->attr_timeout = $milliseconds;
0 ignored issues
show
Bug introduced by
The property attr_timeout does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
118 1
        return $this;
119
    }
120
121
    /**
122
     * Get all assets
123
     *
124
     * @return array|null
125
     */
126 7
    public function getAssets()
127
    {
128 7
        return $this->assets;
129
    }
130
}
131