Total Complexity | 9 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | class PlatformNullFile implements UnescapedFileInterface |
||
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 | 5 | public function __construct(?string $platform = null) |
|
28 | { |
||
29 | 5 | if ($platform === null) { |
|
30 | 3 | $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 | 4 | $this->platform = mb_strtoupper($platform); |
|
40 | 4 | } |
|
41 | |||
42 | 3 | public static function getCurrentPlatform(): string |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * Return /dev/null on linux/unix/mac or NUL on windows. |
||
50 | */ |
||
51 | 4 | public function getNullFile(?string $platform = null): string |
|
62 | } |
||
63 | } |
||
64 | |||
65 | 3 | public function getFile(): string |
|
70 |
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.