Passed
Push — feature/reset-cache-from-class... ( b5ffe1...0b1fbf )
by Chema
03:12
created

Gacela   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 43
ccs 13
cts 16
cp 0.8125
rs 10
c 5
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 20 3
A normalizeSetup() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\Bootstrap\SetupGacela;
9
use Gacela\Framework\Bootstrap\SetupGacelaInterface;
10
use Gacela\Framework\ClassResolver\AbstractClassResolver;
11
use Gacela\Framework\Config\Config;
12
13
use function is_callable;
14
15
final class Gacela
16
{
17
    /**
18
     * Define the entry point of Gacela.
19
     *
20
     * @param null|SetupGacelaInterface|callable(GacelaConfig):void $configFn SetupGacelaInterface is deprecated
21
     */
22 26
    public static function bootstrap(string $appRootDir, $configFn = null): void
23
    {
24 26
        if ($configFn instanceof SetupGacelaInterface) {
25
            trigger_deprecation(
26
                'gacela-project/gacela',
27
                '0.18',
28
                '`SetupGacelaInterface` is deprecated. Use `callable(GacelaConfig)` instead.'
29
            );
30
        }
31
32 26
        $setup = self::normalizeSetup($configFn);
33
34 26
        if (!$setup->isClassResolverCached()) {
35
            AbstractClassResolver::resetCache();
36
        }
37
38 26
        Config::getInstance()
39 26
            ->setAppRootDir($appRootDir)
40 26
            ->setSetup($setup)
41 26
            ->init();
42
    }
43
44
    /**
45
     * @param null|SetupGacelaInterface|callable(GacelaConfig):void $configFn
46
     */
47 26
    private static function normalizeSetup($configFn): SetupGacelaInterface
48
    {
49 26
        if ($configFn === null) {
50 16
            return new SetupGacela();
51
        }
52
53 10
        if (is_callable($configFn)) {
54 10
            return SetupGacela::fromCallable($configFn);
0 ignored issues
show
Bug introduced by
It seems like $configFn can also be of type Gacela\Framework\Bootstrap\SetupGacelaInterface; however, parameter $setupGacelaFileFn of Gacela\Framework\Bootstr...pGacela::fromCallable() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

54
            return SetupGacela::fromCallable(/** @scrutinizer ignore-type */ $configFn);
Loading history...
55
        }
56
57
        return $configFn;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $configFn could return the type callable which is incompatible with the type-hinted return Gacela\Framework\Bootstrap\SetupGacelaInterface. Consider adding an additional type-check to rule them out.
Loading history...
58
    }
59
}
60