PharSupport::clearMocks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation;
6
7
use Hyde\Hyde;
8
use Phar;
9
10
use function dirname;
11
use function is_dir;
12
use function rtrim;
13
use function str_replace;
14
15
/**
16
 * Provides experimental support for running the HydeCLI in a standalone Phar archive.
17
 *
18
 * @experimental
19
 *
20
 * @internal
21
 */
22
class PharSupport
23
{
24
    /** @var array<string, bool> */
25
    protected static array $mocks = [];
26
27
    public static function mock(string $method, bool $value): void
28
    {
29
        self::$mocks[$method] = $value;
30
    }
31
32
    public static function clearMocks(): void
33
    {
34
        self::$mocks = [];
35
    }
36
37
    public static function running(): bool
38
    {
39
        return self::$mocks['running'] ?? Phar::running() !== '';
40
    }
41
42
    public static function hasVendorDirectory(): bool
43
    {
44
        return self::$mocks['hasVendorDirectory'] ?? is_dir(Hyde::path('vendor'));
0 ignored issues
show
Bug introduced by
The method path() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        return self::$mocks['hasVendorDirectory'] ?? is_dir(Hyde::/** @scrutinizer ignore-call */ path('vendor'));
Loading history...
45
    }
46
47
    public static function vendorPath(string $path = '', string $package = 'framework'): string
48
    {
49
        return rtrim(str_replace('/', DIRECTORY_SEPARATOR, rtrim(dirname(__DIR__, 3).'/'.$package.'/'.$path, '/\\')), '/\\');
50
    }
51
}
52