Passed
Push — master ( 477224...3259b8 )
by Aleksei
06:12 queued 18s
created

BindAlias   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 4
c 1
b 0
f 0
dl 0
loc 14
ccs 2
cts 2
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Boot\Attribute;
6
7
/**
8
 * Attribute to define additional aliases for a method.
9
 * 
10
 * This attribute allows defining multiple aliases for a method in a bootloader class.
11
 * It can be used to bind a method's return value to multiple interface or class names.
12
 * 
13
 * This attribute can be applied multiple times to the same method.
14
 * 
15
 * Example usage:
16
 * ```php
17
 * class MyBootloader extends Bootloader
18
 * {
19
 *     #[BindAlias(LoggerInterface::class, PsrLoggerInterface::class)]
20
 *     #[BindAlias(MonologLoggerInterface::class)]
21
 *     public function createLogger(): Logger
22
 *     {
23
 *         return new Logger();
24
 *     }
25
 * }
26
 * ```
27
 * 
28
 * The above example binds the returned Logger instance to LoggerInterface, 
29
 * PsrLoggerInterface, and MonologLoggerInterface.
30
 */
31
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
32
final class BindAlias
33
{
34
    /**
35
     * @param non-empty-string[] $aliases List of class or interface names to bind the returned value to.
36
     */
37
    public readonly array $aliases;
38
39
    /**
40
     * @param non-empty-string ...$aliases List of class or interface names to bind the returned value to.
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
41
     */
42 1
    public function __construct(string ...$aliases)
43
    {
44 1
        $this->aliases = $aliases;
0 ignored issues
show
Bug introduced by
The property aliases is declared read-only in Spiral\Boot\Attribute\BindAlias.
Loading history...
45
    }
46
}
47