Passed
Push — feature/reset-cache-from-abstr... ( a5e9c2...ccf444 )
by Jesús
03:46 queued 36s
created

Gacela::bootstrap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 16
rs 9.9332
c 1
b 0
f 0
ccs 7
cts 8
cp 0.875
crap 2.0078
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\Config\Config;
11
12
use function is_callable;
13
14
final class Gacela
15
{
16
    /**
17
     * Define the entry point of Gacela.
18
     *
19
     * @param null|SetupGacelaInterface|callable(GacelaConfig):void $configFn SetupGacelaInterface is deprecated
20
     */
21 26
    public static function bootstrap(string $appRootDir, $configFn = null): void
22
    {
23 26
        if ($configFn instanceof SetupGacelaInterface) {
24
            trigger_deprecation(
25
                'gacela-project/gacela',
26
                '0.18',
27
                '`SetupGacelaInterface` is deprecated. Use `callable(GacelaConfig)` instead.'
28
            );
29
        }
30
31 26
        $setup = self::normalizeSetup($configFn);
32
33 26
        Config::getInstance()
34 26
            ->setAppRootDir($appRootDir)
35 26
            ->setSetup($setup)
36 26
            ->init();
37
    }
38
39
    /**
40
     * @param null|SetupGacelaInterface|callable(GacelaConfig):void $configFn
41
     */
42 26
    private static function normalizeSetup($configFn): SetupGacelaInterface
43
    {
44 26
        if ($configFn === null) {
45 16
            return new SetupGacela();
46
        }
47
48 10
        if (is_callable($configFn)) {
49 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

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