anonymous//tests/Feature/Framework/BindingInterfacesInGacelaConfigFile/gacela.php$1   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 4
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A gacela.php$1 ➔ getClassName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
use Gacela\Framework\Bootstrap\GacelaConfig;
6
use GacelaTest\Feature\Framework\BindingInterfacesInGacelaConfigFile\Module\Domain\AbstractClass;
7
use GacelaTest\Feature\Framework\BindingInterfacesInGacelaConfigFile\Module\Domain\AbstractFromAnonymousClass;
8
use GacelaTest\Feature\Framework\BindingInterfacesInGacelaConfigFile\Module\Domain\AbstractFromCallable;
9
use GacelaTest\Feature\Framework\BindingInterfacesInGacelaConfigFile\Module\Domain\InterfaceFromAnonymousClass;
10
use GacelaTest\Feature\Framework\BindingInterfacesInGacelaConfigFile\Module\Domain\InterfaceFromCallable;
11
use GacelaTest\Feature\Framework\BindingInterfacesInGacelaConfigFile\Module\Infrastructure\ConcreteClass;
12
13
// Is it also possible to bind classes like => AbstractClass::class => SpecificClass::class
14
// Check the test BindingInterfacesWithInnerDependencies BUT be aware this way is not possible
15
// if the class has dependencies that cannot be resolved automatically!
16
return static fn (GacelaConfig $config): GacelaConfig => $config
17
    ->addBinding(
18
        AbstractClass::class,
19
        new ConcreteClass(true, 'string', 1, 1.2, ['array']),
20
    )
21
    // Resolve anonymous-classes/callables from abstract classes and interfaces
22
    ->addBinding(
23
        AbstractFromAnonymousClass::class,
24
        new class() extends AbstractFromAnonymousClass {
25
            public function getClassName(): string
26
            {
27
                return AbstractFromAnonymousClass::class;
28
            }
29
        },
30
    )
31
    ->addBinding(
32
        AbstractFromCallable::class,
33
        static fn (): AbstractFromCallable => new class() extends AbstractFromCallable {
34
            public function getClassName(): string
35
            {
36
                return AbstractFromCallable::class;
37
            }
38
        },
39
    )
40
    ->addBinding(
41
        InterfaceFromAnonymousClass::class,
42
        new class() implements InterfaceFromAnonymousClass {
43
            public function getClassName(): string
44
            {
45
                return InterfaceFromAnonymousClass::class;
46
            }
47
        },
48
    )
49
    ->addBinding(
50
        InterfaceFromCallable::class,
51
        static fn (): InterfaceFromCallable => new class() implements InterfaceFromCallable {
52
            public function getClassName(): string
53
            {
54
                return InterfaceFromCallable::class;
55
            }
56
        },
57
    );
58