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

AopInfo::hasBindings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
}