Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
SameNameAsClassPolicy | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
methodFor | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | /** |
6 | * Copyright (c) 2019-2023 NxtLvl Software Solutions. |
7 | * |
8 | * Freely available to use under the terms of the MIT license. |
9 | */ |
10 | |
11 | namespace NxtLvlSoftware\StaticConstructors\Policy\Class; |
12 | |
13 | use ReflectionClass; |
14 | use ReflectionMethod; |
15 | |
16 | /** |
17 | * Class policy for classes which define a static constructor with |
18 | * the same name as the class. |
19 | */ |
20 | final class SameNameAsClassPolicy implements StaticConstructorClassPolicy { |
21 | |
22 | /** |
23 | * Retrieve the reflection information for a method with the same |
24 | * name as the class if it exists. |
25 | */ |
26 | public static function methodFor(ReflectionClass $class): ?ReflectionMethod { |
27 | $name = $class->getShortName(); |
28 | return $class->hasMethod($name) ? |
29 | $class->getMethod($class->getShortName()) : null; |
30 | } |
31 | |
32 | } |