ConfigResolverAwareTrait::getConfig()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework;
6
7
use Gacela\Framework\ClassResolver\Config\ConfigResolver;
8
9
/**
10
 * @template TConfig of AbstractConfig
11
 */
12
trait ConfigResolverAwareTrait
13
{
14
    /** @var TConfig|null */
15
    private ?AbstractConfig $config = null;
16
17
    /**
18
     * @return TConfig
19
     */
20
    public function getConfig(): AbstractConfig
21
    {
22
        if ($this->config === null) {
23
            $resolved = (new ConfigResolver())->resolve($this);
24
            /** @var TConfig $resolved */
25
            $this->config = $resolved;
26
        }
27
28
        return $this->config;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->config could return the type null which is incompatible with the type-hinted return Gacela\Framework\AbstractConfig. Consider adding an additional type-check to rule them out.
Loading history...
29
    }
30
}
31