Passed
Push — feature/container-factory ( 5aed48...636d71 )
by Chema
03:27
created

DependencyProvider::addRandomSeed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 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\Feature\Framework\ContainerFactory\Module;
6
7
use Gacela\Framework\AbstractDependencyProvider;
8
use Gacela\Framework\Container\Container;
9
use GacelaTest\Fixtures\StringValue;
10
11
final class DependencyProvider extends AbstractDependencyProvider
12
{
13
    public const CACHED_SEED = 'CACHED_SEED';
14
    public const RANDOM_SEED = 'RANDOM_SEED';
15
    public const RANDOM_STRING_VALUE = 'RANDOM_STRING_VALUE';
16
17
    public function provideModuleDependencies(Container $container): void
18
    {
19
        $this->addCacheSeed($container);
20
        $this->addRandomSeed($container);
21
        $this->addRandomStringValue($container);
22
    }
23
24
    private function addCacheSeed(Container $container): void
25
    {
26
        $container->set(
27
            self::CACHED_SEED,
28
            static fn () => (string)random_int(0, PHP_INT_MAX)
29
        );
30
    }
31
32
    private function addRandomSeed(Container $container): void
33
    {
34
        $container->set(
35
            self::RANDOM_SEED,
36
            $container->factory(static fn () => (string)random_int(0, PHP_INT_MAX))
0 ignored issues
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type object expected by parameter $service of Gacela\Framework\Container\Container::factory(). ( Ignorable by Annotation )

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

36
            $container->factory(/** @scrutinizer ignore-type */ static fn () => (string)random_int(0, PHP_INT_MAX))
Loading history...
37
        );
38
    }
39
40
    private function addRandomStringValue(Container $container): void
41
    {
42
        $container->set(
43
            self::RANDOM_STRING_VALUE,
44
            $container->factory(static function (Container $container) {
0 ignored issues
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type object expected by parameter $service of Gacela\Framework\Container\Container::factory(). ( Ignorable by Annotation )

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

44
            $container->factory(/** @scrutinizer ignore-type */ static function (Container $container) {
Loading history...
45
                /** @var string $cached */
46
                $cached = $container->get(self::CACHED_SEED);
47
48
                /** @var string $random */
49
                $random = $container->get(self::RANDOM_SEED);
50
51
                return new StringValue($cached . $random);
52
            })
53
        );
54
    }
55
}
56