Update dependencies

This commit is contained in:
R. Eric Wheeler 2024-07-18 12:34:40 -07:00
parent 6405f1c7b9
commit d9af97eab2
11 changed files with 2739 additions and 2709 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.php_cs.cache
vendor/
.phpunit.cache/
tools/php-cs-fixer/vendor/

View File

@ -1,11 +1,12 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('var')
;
use PhpCsFixer\Config;
return PhpCsFixer\Config::create()
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
;
return (new Config())
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],

View File

@ -3,13 +3,11 @@
"description": "Implements _getch and _ungetch for windows and linux using ffi",
"type": "library",
"require": {
"php": ">=7.4",
"php": "^8.2",
"ext-ffi": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18",
"jetbrains/phpstorm-stubs": "dev-master",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.6"
},
"autoload": {
"psr-4": {

2845
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,19 +15,15 @@ declare(strict_types=1);
use Sikofitt\Console\Getch;
if (!function_exists('getch')) {
function getch(string $linuxLibrary = null): int
function getch(?string $linuxLibrary = null): int
{
$g = new Getch($linuxLibrary);
return $g->getch();
return (new Getch($linuxLibrary))->getch();
}
}
if (!function_exists('ungetch')) {
function ungetch($char, string $linuxLibrary = null): int
function ungetch($char, ?string $linuxLibrary = null): int
{
$g = new Getch($linuxLibrary);
return $g->ungetch($char);
return (new Getch($linuxLibrary))->ungetch($char);
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace Sikofitt\Console;
use FFI;
use RuntimeException;
final class Getch
{
@ -60,10 +59,10 @@ final class Getch
public static function resetFFI(): void
{
static::$ffi = null;
self::$ffi = null;
}
public function __construct(string $linuxLibrary = null)
public function __construct(?string $linuxLibrary = null)
{
if (null === $linuxLibrary) {
$linuxLibrary = self::LINUX_LIBRARY;
@ -76,12 +75,12 @@ final class Getch
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));
throw new \RuntimeException(sprintf('Could not find library file %s.', $linuxLibrary));
}
$declarations = self::DECLARATIONS.' int cinPeek();';
self::$ffi = FFI::cdef($declarations, $linuxLibrary);
} else {
throw new RuntimeException(sprintf('Sorry, %s is not supported yet.', $osFamily));
throw new \RuntimeException(sprintf('Sorry, %s is not supported yet.', $osFamily));
}
}
}
@ -89,9 +88,9 @@ final class Getch
public function peek(): int
{
if (PHP_OS_FAMILY === 'Windows') {
if ($ffi->_kbhit()) {
$result = $ffi->_getch();
$ffi->_ungetch($result);
if (self::$ffi->_kbhit()) {
$result = self::$ffi->_getch();
self::$ffi->_ungetch($result);
return $result;
}
@ -99,7 +98,7 @@ final class Getch
return -1;
}
return $ffi->cinPeek();
return self::$ffi->cinPeek();
}
public function getch(): int
@ -107,11 +106,8 @@ final class Getch
return self::$ffi->_getch();
}
public function ungetch($char): int
public function ungetch(string|int $char): int
{
if (!is_string($char) && !is_int($char)) {
throw new \TypeError('ungetch takes a parameter of int or string.');
}
if (is_string($char)) {
$char = ord($char[0]);

0
src/Console/Resources/libgetch.so Executable file → Normal file
View File

View File

@ -23,7 +23,9 @@ class GetchTest extends TestCase
/**
* @preserveGlobalState disabled
*
* @backupStaticAttributes false
*
* @backupGlobals false
*/
public function testFailureOnInvalidLibrary()

View File

@ -0,0 +1,5 @@
{
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.59"
}
}

2542
tools/php-cs-fixer/composer.lock generated Normal file

File diff suppressed because it is too large Load Diff