Passed
Push — feature/deprecated-SetupGacela... ( be7b9b )
by Chema
03:53
created

Gacela   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
c 3
b 0
f 0
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 16 2
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
11
use function is_callable;
12
13
final class Gacela
14
{
15
    /**
16
     * Define the entry point of Gacela.
17
     *
18
     * @param null|SetupGacelaInterface|callable(GacelaConfig):void $configFn SetupGacelaInterface is deprecated
19
     */
20 25
    public static function bootstrap(string $appRootDir, $configFn = null): void
21
    {
22 25
        if ($configFn instanceof SetupGacelaInterface) {
23 7
            trigger_deprecation(
24
                'gacela-project/gacela',
25
                '0.18',
26
                '`SetupGacelaInterface` is deprecated and it will be removed in a future version. Use `callable(GacelaConfig)` instead.'
27
            );
28
        }
29
30 25
        $setup = self::normalizeSetup($configFn);
31
32 25
        Config::getInstance()
33 25
            ->setAppRootDir($appRootDir)
34 25
            ->setSetup($setup)
35 25
            ->init();
36
    }
37
38
    /**
39
     * @param null|SetupGacelaInterface|callable(GacelaConfig):void $configFn
40
     */
41 25
    private static function normalizeSetup($configFn): SetupGacelaInterface
42
    {
43 25
        if ($configFn === null) {
44 16
            return new SetupGacela();
45
        }
46
47 9
        if (is_callable($configFn)) {
48 2
            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

48
            return SetupGacela::fromCallable(/** @scrutinizer ignore-type */ $configFn);
Loading history...
49
        }
50
51 7
        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...
52
    }
53
}
54