B   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 13
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A echo() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
require_once(__DIR__ . '/../vendor/autoload.php');
5
6
use VPA\DI\Container;
7
use VPA\DI\Injectable;
8
9
#[Injectable]
10
class A
11
{
12
13
    public function __construct()
14
    {
15
        echo "\n-----\nA\n";
16
    }
17
18
    public function echo()
19
    {
20
        print("\nThis is Sparta!\n");
21
    }
22
23
}
24
25
#[Injectable]
26
class B
27
{
28
29
    public function __construct(protected A $a, private int $num)
30
    {
31
        echo "\n-----\nB\n";
32
    }
33
34
    public function echo()
35
    {
36
        $this->a->echo();
37
        print("\nThis is Sparta! {$this->num}\n");
38
    }
39
}
40
41
class C
42
{
43
44
    public function __construct(protected A $a)
45
    {
46
        echo "\n-----\nA\n";
47
    }
48
49
    public function echo()
50
    {
51
        $this->a->echo();
52
    }
53
}
54
55
class D extends A {
56
57
}
58
59
try {
60
    $di = new Container();
61
    $di->registerContainers([
62
        'aaaa' => 'B'
63
    ]);
64
    $b = $di->get('aaaa', ['num' => 12]);
65
    $b->echo();
66
    $d = $di->get(D::class);
67
    echo $d instanceof D ? "BubblePropagation is work" : "Library is old";
68
} catch (Exception $e) {
69
    print($e->getMessage() . "\n");
70
}