Code Duplication    Length = 19-22 lines in 2 locations

src/Core/Entity.php 1 location

@@ 152-170 (lines=19) @@
149
     * @throws \AframeVR\Core\Exceptions\BadComponentCallException
150
     * @return object|null
151
     */
152
    public function component(string $component_name)
153
    {
154
        $component_name = strtolower($component_name);
155
        
156
        if (! array_key_exists($component_name, $this->components)) {
157
            $component = sprintf(
158
                '\AframeVR\Core\Components\%s\%sComponent',
159
                ucfirst($component_name),
160
                ucfirst($component_name)
161
            );
162
            if (class_exists($component)) {
163
                $this->components[$component_name] = new $component();
164
            } else {
165
                throw new BadComponentCallException($component_name);
166
            }
167
        }
168
        
169
        return $this->components[$component_name] ?? null;
170
    }
171
172
    /**
173
     * Handle entity components

src/Core/Assets/Mixin.php 1 location

@@ 49-70 (lines=22) @@
46
     * @throws \AframeVR\Core\Exceptions\BadComponentCallException
47
     * @return object|null
48
     */
49
    public function component(string $component_name)
50
    {
51
        $component_name = strtolower($component_name);
52
        
53
        /* Does this mixin already have this component loaded */
54
        if (! array_key_exists($component_name, $this->mock_components)) {
55
            $component = sprintf(
56
                '\AframeVR\Core\Components\%s\%sComponent', 
57
                ucfirst($component_name), 
58
                ucfirst($component_name)
59
            );
60
            /* Does called component exist */
61
            if (class_exists($component)) {
62
                /* Create Closure to mock compnent to be applied to entity using this mixin */
63
                $this->mock_components[$component_name] = new MockComponent;
64
            } else {
65
                throw new BadComponentCallException($component_name);
66
            }
67
        }
68
        
69
        return $this->mock_components[$component_name] ?? null;
70
    }
71
72
    /**
73
     * Handle mixin components