Passed
Push — semantic ( 9e9f01 )
by Akihito
02:35
created

AopInfo   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
c 1
b 0
f 0
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A __toString() 0 16 3
A hasBindings() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\Bindings;
6
7
/**
8
 * Value object representing AOP binding information
9
 */
10
final class AopInfo
11
{
12
    /** @var array<string, list<string>> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, list<string>> at position 4 could not be parsed: Expected '>' at position 4, but found 'list'.
Loading history...
13
    public $methodBindings;
14
15
    /**
16
     * @param array<string, list<string>|list<object>> $methodBindings
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, list<string>|list<object>> at position 4 could not be parsed: Expected '>' at position 4, but found 'list'.
Loading history...
17
     */
18
    public function __construct(array $methodBindings)
19
    {
20
        // Convert objects to string representations if needed
21
        $stringBindings = [];
22
        foreach ($methodBindings as $method => $interceptors) {
23
            $stringBindings[$method] = array_map('strval', $interceptors);
24
        }
25
        $this->methodBindings = $stringBindings;
26
    }
27
28
    /**
29
     * Check if any AOP bindings exist
30
     */
31
    public function hasBindings(): bool
32
    {
33
        return !empty($this->methodBindings);
34
    }
35
36
    /**
37
     * Convert to string representation for compatibility
38
     */
39
    public function __toString(): string
40
    {
41
        if (!$this->hasBindings()) {
42
            return '';
43
        }
44
45
        $log = ' (aop)';
46
        foreach ($this->methodBindings as $method => $interceptors) {
47
            $log .= \sprintf(
48
                ' +%s(%s)',
49
                $method,
50
                \implode(', ', $interceptors)
51
            );
52
        }
53
54
        return $log;
55
    }
56
}