Completed
Push — master ( 7dbb7d...8ec63e )
by Marko
02:39
created

EntityChildrenFactory::box()   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 Jul 5, 2016 - 3:05:38 AM
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         EntityChildrenFactory.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\Helpers;
25
26
use \AframeVR\Core\Entity;
27
use \AframeVR\Core\Exceptions\BadPrimitiveCallException;
28
29
class EntityChildrenFactory
30
{
31
    /**
32
     * Child entities
33
     *
34
     * @var array
35
     */
36
    protected $childrens = array();
37
38
    /**
39
     * Entity
40
     *
41
     * @api
42
     *
43
     * @param string $id            
44
     * @return \AframeVR\Core\Entity
45
     */
46 5
    public function entity(string $id = 'untitled'): Entity
47
    {
48 5
        return $this->childrens[$id] ?? $this->childrens[$id] = new Entity($id);
49
    }
50
51
    /**
52
     * Call
53
     *
54
     * @param string $method
55
     * @param array $args
56
     * @throws BadShaderCallException
57
     * @return Entity|\AframeVR\Interfaces\ComponentInterface
58
     */
59 4 View Code Duplication
    public function __call(string $method, 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...
60
    {
61 4
        $id        = $args[0] ?? 'untitled';
62 4
        $primitive = sprintf('\AframeVR\Extras\Primitives\%s',  ucfirst($method));
63
    
64 4
        if (class_exists($primitive)) {
65 3
            return $this->childrens[$id] ?? $this->childrens[$id] = new $primitive($id);
66
        } else {
67 1
            throw new BadPrimitiveCallException($method);
68
        }
69
    }
70
    
71 2
    public function getChildern()
72
    {
73 2
        return $this->childrens;
74
    }
75
}