AbstractExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypes() 0 3 1
A register() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\Postgres\Extensions;
6
7
use Illuminate\Support\Traits\Macroable;
8
use Umbrellio\Postgres\Extensions\Exceptions\MacroableMissedException;
9
use Umbrellio\Postgres\Extensions\Exceptions\MixinInvalidException;
10
11
/**
12
 * @codeCoverageIgnore
13
 */
14
abstract class AbstractExtension extends AbstractComponent
15
{
16
    abstract public static function getMixins(): array;
17
18
    abstract public static function getName(): string;
19
20
    public static function getTypes(): array
21
    {
22
        return [];
23
    }
24
25
    final public static function register(): void
26
    {
27
        collect(static::getMixins())->each(static function ($extension, $mixin) {
0 ignored issues
show
Bug introduced by
static::getMixins() of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        collect(/** @scrutinizer ignore-type */ static::getMixins())->each(static function ($extension, $mixin) {
Loading history...
28
            if (! is_subclass_of($mixin, AbstractComponent::class)) {
29
                throw new MixinInvalidException(sprintf(
30
                    'Mixed class %s is not descendant of %s.',
31
                    $mixin,
32
                    AbstractComponent::class
33
                ));
34
            }
35
            if (! method_exists($extension, 'mixin')) {
36
                throw new MacroableMissedException(sprintf('Class %s doesn’t use Macroable Trait.', $extension));
37
            }
38
            /** @var Macroable $extension */
39
            $extension::mixin(new $mixin());
40
        });
41
    }
42
}
43