diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f2f0b44..4bc58a9 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,14 +2,17 @@ use PhpCsFixer\Config; +$header = file_exists(__DIR__.'/header.txt') ? file_get_contents(__DIR__.'/header.txt') : ''; $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests') ; return (new Config()) + ->setRules([ '@Symfony' => true, 'array_syntax' => ['syntax' => 'short'], + 'header_comment' => ['header' => $header], ]) ->setFinder($finder) ; diff --git a/functions.php b/functions.php index f75f3a5..3cd0f6c 100644 --- a/functions.php +++ b/functions.php @@ -3,7 +3,7 @@ declare(strict_types=1); /* - * Copyright (c) 2020 https://rewiv.com sikofitt@gmail.com + * Copyright (c) 2020-2024 https://sikofitt.com sikofitt@gmail.com * * This Source Code Form is subject to the * terms of the Mozilla Public License, v. 2.0. diff --git a/header.txt b/header.txt index a30ee42..3aedd39 100644 --- a/header.txt +++ b/header.txt @@ -1,4 +1,4 @@ -Copyright (c) 2020 https://rewiv.com sikofitt@gmail.com +Copyright (c) 2020-2024 https://sikofitt.com sikofitt@gmail.com This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. diff --git a/src/Console/Getch.php b/src/Console/Getch.php index 2ede5ae..e10947f 100644 --- a/src/Console/Getch.php +++ b/src/Console/Getch.php @@ -3,7 +3,7 @@ declare(strict_types=1); /* - * Copyright (c) 2020 https://rewiv.com sikofitt@gmail.com + * Copyright (c) 2020-2024 https://sikofitt.com sikofitt@gmail.com * * This Source Code Form is subject to the * terms of the Mozilla Public License, v. 2.0. @@ -14,8 +14,6 @@ declare(strict_types=1); namespace Sikofitt\Console; -use FFI; - final class Getch { // Special key codes @@ -24,7 +22,7 @@ final class Getch public const KEY_E0 = 0; public const KEY_E1 = 224; - // Supported scan scodes. + // Supported scan codes. public const KEY_F1 = 59; public const KEY_F2 = 60; public const KEY_F3 = 61; @@ -55,7 +53,7 @@ final class Getch int _ungetch(int c); DECLARATIONS; - private static ?FFI $ffi = null; + private static ?\FFI $ffi = null; public static function resetFFI(): void { @@ -72,13 +70,13 @@ final class Getch $osFamily = PHP_OS_FAMILY; if ('Windows' === $osFamily) { $declarations = self::DECLARATIONS.' int _kbhit();'; - self::$ffi = FFI::cdef($declarations, self::WINDOWS_LIBRARY); + self::$ffi = \FFI::cdef($declarations, self::WINDOWS_LIBRARY); } elseif ('Linux' === $osFamily) { if (!file_exists($linuxLibrary)) { throw new \RuntimeException(sprintf('Could not find library file %s.', $linuxLibrary)); } $declarations = self::DECLARATIONS.' int cinPeek();'; - self::$ffi = FFI::cdef($declarations, $linuxLibrary); + self::$ffi = \FFI::cdef($declarations, $linuxLibrary); } else { throw new \RuntimeException(sprintf('Sorry, %s is not supported yet.', $osFamily)); } @@ -108,7 +106,6 @@ final class Getch public function ungetch(string|int $char): int { - if (is_string($char)) { $char = ord($char[0]); } diff --git a/tests/Getch/GetchTest.php b/tests/Getch/GetchTest.php index ad293fa..36fdd65 100644 --- a/tests/Getch/GetchTest.php +++ b/tests/Getch/GetchTest.php @@ -1,5 +1,15 @@