ModuleString::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 22
c 1
b 0
f 0
rs 9.8333
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Aop\Pointcut;
8
9
use function assert;
10
use function implode;
11
use function serialize;
12
use function sort;
13
use function sprintf;
14
use function unserialize;
15
16
use const PHP_EOL;
17
18
final class ModuleString
19
{
20
    /**
21
     * @param array<int, Pointcut> $pointcuts
22
     */
23
    public function __invoke(Container $container, array $pointcuts): string
24
    {
25
        $log = [];
26
        /** @psalm-suppress MixedAssignment */
27
        $container = unserialize(serialize($container), ['allowed_classes' => true]);
28
        assert($container instanceof Container);
29
        $spy = new SpyCompiler();
30
        foreach ($container->getContainer() as $dependencyIndex => $dependency) {
31
            if ($dependency instanceof Dependency) {
32
                $dependency->weaveAspects($spy, $pointcuts);
33
            }
34
35
            $log[] = sprintf(
36
                '%s => %s',
37
                $dependencyIndex,
38
                (string) $dependency
39
            );
40
        }
41
42
        sort($log);
43
44
        return implode(PHP_EOL, $log);
45
    }
46
}
47