Total Complexity | 8 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | class PlatformNullFile |
||
10 | { |
||
11 | public const PLATFORM_LINUX = 'LINUX'; |
||
12 | public const PLATFORM_WIN = 'WINDOWS'; |
||
13 | |||
14 | public const SUPPORTED_PLATFORMS = [ |
||
15 | self::PLATFORM_LINUX, |
||
16 | self::PLATFORM_WIN, |
||
17 | ]; |
||
18 | |||
19 | /** @var string $platform if null platform wil be auto detected */ |
||
20 | protected $platform; |
||
21 | |||
22 | /** |
||
23 | * @param null|string $platform if null platform will be autodetected |
||
24 | * |
||
25 | * @throws InvalidArgumentException |
||
26 | */ |
||
27 | 3 | public function __construct(?string $platform = null) |
|
28 | { |
||
29 | 3 | if ($platform === null) { |
|
30 | 1 | $platform = self::getCurrentPlatform(); |
|
31 | } else { |
||
32 | 2 | if (!in_array(mb_strtoupper($platform), self::SUPPORTED_PLATFORMS, true)) { |
|
33 | 1 | throw new InvalidArgumentException(sprintf( |
|
34 | 1 | 'Platform \'%s\' is not supported', |
|
35 | 1 | $platform |
|
36 | )); |
||
37 | } |
||
38 | } |
||
39 | 2 | $this->platform = mb_strtoupper($platform); |
|
40 | 2 | } |
|
41 | |||
42 | 1 | public static function getCurrentPlatform(): string |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * Return /dev/null on linux/unix/mac or NUL on windows. |
||
50 | */ |
||
51 | 2 | public function getNullFile(): string |
|
60 | } |
||
61 | } |
||
63 |