Passed
Pull Request — main (#333)
by Chema
08:07 queued 04:04
created

AbstractFacade   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 6
c 0
b 0
f 0
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resetCache() 0 3 1
A getFactory() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework;
6
7
use Gacela\Framework\ClassResolver\Factory\FactoryResolver;
8
9
/**
10
 * @template TFactory of AbstractFactory = AbstractFactory
11
 */
12
abstract class AbstractFacade
13
{
14
    /** @var array<string, AbstractFactory> */
15
    private static array $factories = [];
16
17
    public static function resetCache(): void
18
    {
19
        self::$factories = [];
20
    }
21
22
    /**
23
     * @return TFactory
24
     */
25
    public function getFactory(): AbstractFactory
26
    {
27
        $factory = self::$factories[static::class]
28
            ??= (new FactoryResolver())->resolve(static::class);
29
30
        /** @var TFactory $factory */
31
        return $factory;
32
    }
33
}
34