Passed
Push — master ( 56f868...92a432 )
by Caen
12:09 queued 33s
created

MockableFeatures::mock()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Concerns\Internal;
6
7
/**
8
 * @internal
9
 */
10
trait MockableFeatures
11
{
12
    protected static array $mockedInstances = [];
13
14
    public static function mock(string|array $feature, ?bool $enabled = null): void
15
    {
16
        if (is_array($feature)) {
0 ignored issues
show
introduced by
The condition is_array($feature) is always true.
Loading history...
17
            foreach ($feature as $key => $value) {
18
                static::mock($key, $value);
19
            }
20
21
            return;
22
        }
23
24
        static::$mockedInstances[$feature] = $enabled;
25
    }
26
27
    public static function resolveMockedInstance(string $feature): ?bool
28
    {
29
        return static::$mockedInstances[$feature] ?? null;
30
    }
31
32
    public static function clearMockedInstances(): void
33
    {
34
        static::$mockedInstances = [];
35
    }
36
}
37