Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
PhpStyleConstructorPolicy
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 methodFor
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(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
11namespace NxtLvlSoftware\StaticConstructors\Policy\Class;
12
13use ReflectionClass;
14use ReflectionMethod;
15
16/**
17 * Class policy for classes which define a static constructor with
18 * the `__constructStatic()` magic method.
19 */
20final class PhpStyleConstructorPolicy implements StaticConstructorClassPolicy {
21
22    private const CONSTRUCTOR_METHOD_NAME = '__constructStatic';
23
24    /**
25     * Retrieve the reflection information for a method named `__constructStatic`
26     * if it exists.
27     */
28    public static function methodFor(ReflectionClass $class): ?ReflectionMethod {
29        return $class->hasMethod(self::CONSTRUCTOR_METHOD_NAME) ?
30            $class->getMethod(self::CONSTRUCTOR_METHOD_NAME) : null;
31    }
32
33}