Passed
Push — feat/split-anonymousglobalsben... ( 041af8 )
by Jesús
06:16
created

AnonymousGlobalsBench.php$2 ➔ abstractFactory()   A

Complexity

Conditions 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 33
cc 1
rs 9.392

4 Methods

Rating   Name   Duplication   Size   Complexity  
A AnonymousGlobalsBench.php$2 ➔ getConfigValues() 0 3 1
A AnonymousGlobalsBench.php$2 ➔ __construct() 0 6 1
A AnonymousGlobalsBench.php$2 ➔ createDomainClass() 0 28 1
A AnonymousGlobalsBench.php$2 ➔ getValueFromDependencyProvider() 0 3 1
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\AbstractDependencyProvider;
9
use Gacela\Framework\AbstractFacade;
10
use Gacela\Framework\AbstractFactory;
11
use Gacela\Framework\ClassResolver\GlobalInstance\AnonymousGlobal;
12
use Gacela\Framework\Container\Container;
13
14
/**
15
 * @BeforeMethods("setUp")
16
 */
17
final class AnonymousGlobalsBench
18
{
19
    private AbstractFacade $facade;
20
21
    public function setUp(): void
22
    {
23
        $this->abstractConfig();
24
        $this->abstractDependencyProvider();
25
        $this->abstractFactory();
26
        $this->abstractFacade();
27
    }
28
29
    public function bench_class_resolving(): void
30
    {
31
        $this->facade->getConfigValues();
0 ignored issues
show
Bug introduced by
The method getConfigValues() does not exist on Gacela\Framework\AbstractFacade. It seems like you code against a sub-type of Gacela\Framework\AbstractFacade such as anonymous//tests/Benchma...ymousGlobalsBench.php$4 or GacelaTest\Benchmark\Fra...dule\NormalModuleFacade. ( Ignorable by Annotation )

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

31
        $this->facade->/** @scrutinizer ignore-call */ 
32
                       getConfigValues();
Loading history...
32
        $this->facade->getValueFromDependencyProvider();
0 ignored issues
show
Bug introduced by
The method getValueFromDependencyProvider() does not exist on Gacela\Framework\AbstractFacade. It seems like you code against a sub-type of Gacela\Framework\AbstractFacade such as anonymous//tests/Benchma...ymousGlobalsBench.php$4 or GacelaTest\Benchmark\Fra...dule\NormalModuleFacade. ( Ignorable by Annotation )

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

32
        $this->facade->/** @scrutinizer ignore-call */ 
33
                       getValueFromDependencyProvider();
Loading history...
33
    }
34
35
    private function abstractConfig(): void
36
    {
37
        AnonymousGlobal::addGlobal(
38
            $this,
39
            new class() extends AbstractConfig {
40
                public function getValues(): array
41
                {
42
                    return ['1', 2, [3]];
43
                }
44
            }
45
        );
46
    }
47
48
    private function abstractDependencyProvider(): void
49
    {
50
        AnonymousGlobal::addGlobal(
51
            $this,
52
            new class() extends AbstractDependencyProvider {
53
                public function provideModuleDependencies(Container $container): void
54
                {
55
                    $container->set('key', 'value');
56
                }
57
            }
58
        );
59
    }
60
61
    private function abstractFactory(): void
62
    {
63
        AnonymousGlobal::addGlobal(
64
            $this,
65
            new class() extends AbstractFactory {
66
                public function createDomainClass(): object
67
                {
68
                    /** @var array $configValues */
69
                    $configValues = $this->getConfig()->getValues();
70
71
                    /** @var string $valueFromDependencyProvider */
72
                    $valueFromDependencyProvider = $this->getProvidedDependency('key');
73
74
                    return new class($configValues, $valueFromDependencyProvider) {
75
                        private array $configValues;
76
                        private string $valueFromDependencyProvider;
77
78
                        public function __construct(
79
                            array $configValues,
80
                            string $valueFromDependencyProvider
81
                        ) {
82
                            $this->configValues = $configValues;
83
                            $this->valueFromDependencyProvider = $valueFromDependencyProvider;
84
                        }
85
86
                        public function getConfigValues(): array
87
                        {
88
                            return $this->configValues;
89
                        }
90
91
                        public function getValueFromDependencyProvider(): string
92
                        {
93
                            return $this->valueFromDependencyProvider;
94
                        }
95
                    };
96
                }
97
            }
98
        );
99
    }
100
101
    private function abstractFacade(): void
102
    {
103
        $this->facade = new class() extends AbstractFacade {
104
            public function getConfigValues(): array
105
            {
106
                return $this->getFactory()
107
                    ->createDomainClass()
108
                    ->getConfigValues();
109
            }
110
111
            public function getValueFromDependencyProvider(): string
112
            {
113
                return $this->getFactory()
114
                    ->createDomainClass()
115
                    ->getValueFromDependencyProvider();
116
            }
117
        };
118
    }
119
}
120