Code Duplication    Length = 17-20 lines in 2 locations

src/Core/Assets/Mixin.php 1 location

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

src/Core/Entity.php 1 location

@@ 209-225 (lines=17) @@
206
     * @throws \AframeVR\Core\Exceptions\BadComponentCallException
207
     * @return object|null
208
     */
209
    public function component(string $component_name)
210
    {
211
        if (! array_key_exists($component_name, $this->components)) {
212
            $component = sprintf('\AframeVR\Core\Components\%s\%sComponent', ucfirst($component_name), 
213
                ucfirst($component_name));
214
            if (class_exists($component)) {
215
                $this->components[$component_name] = new $component();
216
            } else {
217
                throw new BadComponentCallException($component_name);
218
            }
219
        }
220
        
221
        return $this->components[$component_name] ?? null;
222
    }
223
224
    /**
225
     * Handle entity components
226
     *
227
     * Since we might need to customize these to have
228
     * custom components loaded as $this->methosd aswell therefore