GacelaGlobalBench.php$1 ➔ setupCustomFactory()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 27
rs 9.488
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A GacelaGlobalBench.php$1 ➔ getValueFromProvider() 0 3 1
A GacelaGlobalBench.php$1 ➔ getConfigValues() 0 3 1
A GacelaGlobalBench.php$1 ➔ createDomainClass() 0 23 1
A GacelaGlobalBench.php$1 ➔ __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Benchmark;
6
7
use Gacela\Framework\AbstractConfig;
8
use Gacela\Framework\AbstractFacade;
9
use Gacela\Framework\AbstractFactory;
10
use Gacela\Framework\AbstractProvider;
11
use Gacela\Framework\Container\Container;
12
use Gacela\Framework\Gacela;
13
14
/**
15
 * @BeforeMethods("setUp")
16
 */
17
final class GacelaGlobalBench
18
{
19
    private AbstractFacade $facade;
20
21
    public function setUp(): void
22
    {
23
        Gacela::bootstrap(__DIR__);
24
25
        $this->setupCustomConfig();
26
        $this->setupCustomProvider();
27
        $this->setupCustomFactory();
28
        $this->setupCustomFacade();
29
    }
30
31
    public function bench_gacela_global(): void
32
    {
33
        $this->facade->getConfigValues();
0 ignored issues
show
Bug introduced by
The method getConfigValues() does not exist on Gacela\Framework\AbstractFacade. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

33
        $this->facade->/** @scrutinizer ignore-call */ 
34
                       getConfigValues();
Loading history...
34
        $this->facade->getValueFromProvider();
0 ignored issues
show
Bug introduced by
The method getValueFromProvider() does not exist on Gacela\Framework\AbstractFacade. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

34
        $this->facade->/** @scrutinizer ignore-call */ 
35
                       getValueFromProvider();
Loading history...
35
    }
36
37
    private function setupCustomFacade(): void
38
    {
39
        $this->facade = new class() extends AbstractFacade {
40
            public function getConfigValues(): array
41
            {
42
                return $this->getFactory()
43
                    ->createDomainClass()
0 ignored issues
show
Bug introduced by
The method createDomainClass() does not exist on Gacela\Framework\AbstractFactory. It seems like you code against a sub-type of Gacela\Framework\AbstractFactory such as GacelaTest\Benchmark\FileCache\ModuleC\FactoryC or GacelaTest\Benchmark\FileCache\ModuleE\FactoryE or GacelaTest\Benchmark\Fil...\ModuleG\ModuleGFactory or GacelaTest\Benchmark\FileCache\ModuleA\FactoryA or GacelaTest\Feature\Frame...ileCache\Module\Factory or anonymous//tests/Integra...nymousClassesTest.php$3 or GacelaTest\Benchmark\FileCache\ModuleB\FactoryB or GacelaTest\Benchmark\FileCache\ModuleD\FactoryD or GacelaTest\Benchmark\Mod...le\ModuleExampleFactory or GacelaTest\Benchmark\FileCache\ModuleF\Factory or anonymous//tests/Benchmark/GacelaGlobalBench.php$2. ( Ignorable by Annotation )

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

43
                    ->/** @scrutinizer ignore-call */ createDomainClass()
Loading history...
44
                    ->getConfigValues();
45
            }
46
47
            public function getValueFromProvider(): string
48
            {
49
                return $this->getFactory()
50
                    ->createDomainClass()
51
                    ->getValueFromProvider();
52
            }
53
        };
54
    }
55
56
    private function setupCustomFactory(): void
57
    {
58
        Gacela::addGlobal(
59
            new class() extends AbstractFactory {
60
                public function createDomainClass(): object
61
                {
62
                    /** @var array $configValues */
63
                    $configValues = $this->getConfig()->getValues();
0 ignored issues
show
Bug introduced by
The method getValues() does not exist on Gacela\Framework\AbstractConfig. It seems like you code against a sub-type of Gacela\Framework\AbstractConfig such as anonymous//tests/Benchmark/GacelaGlobalBench.php$4 or anonymous//tests/Integra...nymousClassesTest.php$1 or GacelaTest\Benchmark\Mod...ple\ModuleExampleConfig. ( Ignorable by Annotation )

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

63
                    $configValues = $this->getConfig()->/** @scrutinizer ignore-call */ getValues();
Loading history...
64
65
                    /** @var string $valueFromProvider */
66
                    $valueFromProvider = $this->getProvidedDependency('key');
67
68
                    return new class($configValues, $valueFromProvider) {
69
                        public function __construct(
70
                            private readonly array $configValues,
71
                            private readonly string $valueFromProvider,
72
                        ) {
73
                        }
74
75
                        public function getConfigValues(): array
76
                        {
77
                            return $this->configValues;
78
                        }
79
80
                        public function getValueFromProvider(): string
81
                        {
82
                            return $this->valueFromProvider;
83
                        }
84
                    };
85
                }
86
            },
87
        );
88
    }
89
90
    private function setupCustomProvider(): void
91
    {
92
        Gacela::addGlobal(
93
            new class() extends AbstractProvider {
94
                public function provideModuleDependencies(Container $container): void
95
                {
96
                    $container->set('key', 'value');
97
                }
98
            },
99
        );
100
    }
101
102
    private function setupCustomConfig(): void
103
    {
104
        Gacela::addGlobal(
105
            new class() extends AbstractConfig {
106
                /**
107
                 * @return list<mixed>
108
                 */
109
                public function getValues(): array
110
                {
111
                    return ['1', 2, [3]];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('1', 2, array(3)) returns the type array<integer,array<inte...nteger>|integer|string> which is incompatible with the documented return type GacelaTest\Benchmark\list.
Loading history...
112
                }
113
            },
114
        );
115
    }
116
}
117