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