Code Duplication    Length = 17-19 lines in 2 locations

src/Core/Assets/Mixin.php 1 location

@@ 48-64 (lines=17) @@
45
     * @throws \AframeVR\Core\Exceptions\BadComponentCallException
46
     * @return object|null
47
     */
48
    public function component(string $component_name)
49
    {
50
        $component_name = strtolower($component_name);
51
        
52
        /* Does this mixin already have this component loaded */
53
        if (! array_key_exists($component_name, $this->components)) {
54
            $component = sprintf('\AframeVR\Core\Components\%s\%sComponent', ucfirst($component_name), ucfirst($component_name));
55
            /* Does called component exist */
56
            if (class_exists($component)) {
57
                $this->components[$component_name] = $this->componentClosure();
58
            } else {
59
                throw new BadComponentCallException($component_name);
60
            }
61
        }
62
        
63
        return $this->components[$component_name] ?? null;
64
    }
65
66
    /**
67
     * Handle mixin components

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