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

InitMethod   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 2
c 1
b 0
f 0
dl 0
loc 9
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 for marking methods that should be called during the initialization phase.
9
 * 
10
 * Methods marked with this attribute will be called during the bootloader's
11
 * initialization phase, before the boot phase begins. This is where you typically
12
 * set up container bindings, register services, or perform other initialization tasks.
13
 * 
14
 * The priority parameter determines the order in which init methods are called.
15
 * Higher priority values are executed first.
16
 * 
17
 * Example usage:
18
 * ```php
19
 * class MyBootloader extends Bootloader
20
 * {
21
 *     // Called during initialization phase with default priority (0)
22
 *     #[InitMethod]
23
 *     public function registerServices(Container $container): void
24
 *     {
25
 *         $container->bindSingleton(MyService::class, MyServiceImplementation::class);
26
 *     }
27
 *     
28
 *     // Called during initialization phase with high priority (10)
29
 *     #[InitMethod(priority: 10)]
30
 *     public function setupCore(): void
31
 *     {
32
 *         // Setup core components first
33
 *     }
34
 *     
35
 *     // Called during initialization phase with low priority (-10)
36
 *     #[InitMethod(priority: -10)]
37
 *     public function setupExtensions(): void
38
 *     {
39
 *         // Setup extensions after core components
40
 *     }
41
 * }
42
 * ```
43
 * 
44
 * Init methods are executed before any bootloader's boot methods are called.
45
 * 
46
 * @see BootMethod For methods to be called during boot phase
47
 */
48
#[\Attribute(\Attribute::TARGET_METHOD)]
49
final class InitMethod
50
{
51
    /**
52
     * @param int $priority The priority of this init method. Higher values are executed first.
53
     */
54 4
    public function __construct(
55
        public readonly int $priority = 0,
56 4
    ) {}
57
}
58