ApplicationDataProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getConsoleContainer() 0 3 1
A getConsoleRunner() 0 9 2
A getConsoleConfig() 0 3 1
A getWebRunner() 0 9 2
A getWebConfig() 0 3 1
A getWebContainer() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Tests\Support;
6
7
use Psr\Container\ContainerInterface;
8
use Yiisoft\Config\Config;
9
use Yiisoft\Yii\Runner\Console\ConsoleApplicationRunner;
10
use Yiisoft\Yii\Runner\Http\HttpApplicationRunner;
11
12
final class ApplicationDataProvider
13
{
14
    private static ?ConsoleApplicationRunner $consoleRunner = null;
15
    private static ?HttpApplicationRunner $webRunner = null;
16
17
    public static function getConsoleConfig(): Config
18
    {
19
        return self::getConsoleRunner()->getConfig();
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::getConsoleRunner()->getConfig() returns the type Yiisoft\Config\ConfigInterface which includes types incompatible with the type-hinted return Yiisoft\Config\Config.
Loading history...
20
    }
21
22
    public static function getConsoleContainer(): ContainerInterface
23
    {
24
        return self::getConsoleRunner()->getContainer();
25
    }
26
27
    public static function getWebConfig(): Config
28
    {
29
        return self::getConsoleRunner()->getConfig();
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::getConsoleRunner()->getConfig() returns the type Yiisoft\Config\ConfigInterface which includes types incompatible with the type-hinted return Yiisoft\Config\Config.
Loading history...
30
    }
31
32
    public static function getWebContainer(): ContainerInterface
33
    {
34
        return self::getConsoleRunner()->getContainer();
35
    }
36
37
    private static function getConsoleRunner(): ConsoleApplicationRunner
38
    {
39
        if (self::$consoleRunner === null) {
40
            self::$consoleRunner = new ConsoleApplicationRunner(
41
                rootPath: dirname(__DIR__, 2),
42
                environment: $_ENV['YII_ENV']
43
            );
44
        }
45
        return self::$consoleRunner;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::consoleRunner could return the type null which is incompatible with the type-hinted return Yiisoft\Yii\Runner\Conso...onsoleApplicationRunner. Consider adding an additional type-check to rule them out.
Loading history...
46
    }
47
48
    private static function getWebRunner(): HttpApplicationRunner
0 ignored issues
show
Unused Code introduced by
The method getWebRunner() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
49
    {
50
        if (self::$webRunner === null) {
51
            self::$webRunner = new HttpApplicationRunner(
52
                rootPath: dirname(__DIR__, 2),
53
                environment: $_ENV['YII_ENV']
54
            );
55
        }
56
        return self::$webRunner;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::webRunner could return the type null which is incompatible with the type-hinted return Yiisoft\Yii\Runner\Http\HttpApplicationRunner. Consider adding an additional type-check to rule them out.
Loading history...
57
    }
58
}
59