AutoGeneratesModuleId   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
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 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A moduleIdOfThisClass() 0 10 2
A getId() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the AutoGeneratesModuleId trait.
7
 *
8
 * @copyright   Copyright (c) 2021 Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2021-11-13
12
 *
13
 */
14
15
namespace Konekt\Concord\Concerns;
16
17
use Konekt\Concord\Contracts\Module;
18
use Konekt\Concord\Utils\ModuleIdGenerator;
19
20
trait AutoGeneratesModuleId
21
{
22
    protected static ?string $moduleId = null;
23
24
    public static function getId(): string
25
    {
26
        if (null === static::$moduleId) {
27
            static::$moduleId = static::moduleIdOfThisClass();
28
        }
29
30
        return static::$moduleId;
31
    }
32
33
    protected static function moduleIdOfThisClass(): string
34
    {
35
        if (is_a_concord_module_class(static::class)) {
36
            return ModuleIdGenerator::idOfClass(static::class, static::getConvention());
37
        }
38
39
        throw new \LogicException(
40
            'The %s class does not implement the %s interface',
41
            static::class,
0 ignored issues
show
Bug introduced by
static::class of type string is incompatible with the type integer expected by parameter $code of LogicException::__construct(). ( Ignorable by Annotation )

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

41
            /** @scrutinizer ignore-type */ static::class,
Loading history...
42
            Module::class,
0 ignored issues
show
Bug introduced by
Konekt\Concord\Contracts\Module::class of type string is incompatible with the type Throwable|null expected by parameter $previous of LogicException::__construct(). ( Ignorable by Annotation )

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

42
            /** @scrutinizer ignore-type */ Module::class,
Loading history...
43
        );
44
    }
45
}
46