Passed
Push — feat/use-provider ( 6f868a...2ac9e4 )
by Chema
03:46
created

  A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Benchmark\Framework\ClassResolver\AnonymousGlobal;
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\ClassResolver\GlobalInstance\AnonymousGlobal;
12
use Gacela\Framework\Container\Container;
13
use Gacela\Framework\Gacela;
14
15
/**
16
 * @BeforeMethods("setUp")
17
 */
18
final class AnonymousGlobalsBench
19
{
20
    private AbstractFacade $facade;
21
22
    public function setUp(): void
23
    {
24
        Gacela::bootstrap(__DIR__);
25
26
        $this->setupAbstractConfig();
27
        $this->setupAbstractProvider();
28
        $this->setupAbstractFactory();
29
        $this->setupAbstractFacade();
30
    }
31
32
    public function bench_class_resolving(): void
33
    {
34
        $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

34
        $this->facade->/** @scrutinizer ignore-call */ 
35
                       getConfigValues();
Loading history...
35
        $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

35
        $this->facade->/** @scrutinizer ignore-call */ 
36
                       getValueFromProvider();
Loading history...
36
    }
37
38
    private function setupAbstractConfig(): void
39
    {
40
        AnonymousGlobal::addGlobal(
41
            $this,
42
            new class() extends AbstractConfig {
43
                public function getValues(): array
44
                {
45
                    return ['1', 2, [3]];
46
                }
47
            },
48
        );
49
    }
50
51
    private function setupAbstractProvider(): void
52
    {
53
        AnonymousGlobal::addGlobal(
54
            $this,
55
            new class() extends AbstractProvider {
56
                public function provideModuleDependencies(Container $container): void
57
                {
58
                    $container->set('key', 'value');
59
                }
60
            },
61
        );
62
    }
63
64
    private function setupAbstractFactory(): void
65
    {
66
        AnonymousGlobal::addGlobal(
67
            $this,
68
            new class() extends AbstractFactory {
69
                public function createDomainClass(): object
70
                {
71
                    /** @var array $configValues */
72
                    $configValues = $this->getConfig()->getValues();
73
74
                    /** @var string $valueFromProvider */
75
                    $valueFromProvider = $this->getProvidedDependency('key');
76
77
                    return new class($configValues, $valueFromProvider) {
78
                        public function __construct(
79
                            private readonly array $configValues,
80
                            private readonly string $valueFromProvider,
81
                        ) {
82
                        }
83
84
                        public function getConfigValues(): array
85
                        {
86
                            return $this->configValues;
87
                        }
88
89
                        public function getValueFromProvider(): string
90
                        {
91
                            return $this->valueFromProvider;
92
                        }
93
                    };
94
                }
95
            },
96
        );
97
    }
98
99
    private function setupAbstractFacade(): void
100
    {
101
        $this->facade = new class() extends AbstractFacade {
102
            public function getConfigValues(): array
103
            {
104
                return $this->getFactory()
105
                    ->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\Fra...eCache\ModuleD\FactoryD or GacelaTest\Benchmark\Fra...leCache\ModuleF\Factory or GacelaTest\Feature\Frame...ileCache\Module\Factory or GacelaTest\Benchmark\Fra...\ModuleG\ModuleGFactory or GacelaTest\Benchmark\Fra...eCache\ModuleC\FactoryC or GacelaTest\Benchmark\Fra...eCache\ModuleE\FactoryE or anonymous//tests/Benchma...ymousGlobalsBench.php$3 or GacelaTest\Benchmark\Fra...ule\NormalModuleFactory or GacelaTest\Benchmark\Fra...eCache\ModuleA\FactoryA or anonymous//tests/Integra...nymousClassesTest.php$3 or GacelaTest\Benchmark\Fra...eCache\ModuleB\FactoryB. ( Ignorable by Annotation )

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

105
                    ->/** @scrutinizer ignore-call */ createDomainClass()
Loading history...
106
                    ->getConfigValues();
107
            }
108
109
            public function getValueFromProvider(): string
110
            {
111
                return $this->getFactory()
112
                    ->createDomainClass()
113
                    ->getValueFromProvider();
114
            }
115
        };
116
    }
117
}
118