Skip to content

Commit

Permalink
Replace psalm to phpstan and fix some linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Dec 4, 2024
1 parent 0d897bd commit d8599c7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
<a href="https://packagist.org/packages/serafim/ffi-sdl"><img src="https://poser.pugx.org/serafim/ffi-sdl/downloads?style=for-the-badge" alt="Total Downloads"></a>
<a href="https://raw.githubusercontent.com/serafim/ffi-sdl/master/LICENSE.md"><img src="https://poser.pugx.org/serafim/ffi-sdl/license?style=for-the-badge" alt="License MIT"></a>
</p>
<p align="center">
<a href="https://github.com/SerafimArts/ffi-sdl/actions"><img src="https://github.com/SerafimArts/ffi-sdl/workflows/build/badge.svg"></a>
</p>

A SDL FFI bindings for the PHP language.

Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ parameters:
inferPrivatePropertyTypeFromConstructor: true
tipsOfTheDay: false
checkMissingCallableSignature: true
ignoreErrors:
- '#^PHPDoc tag @var with type FFI\|object#'
- '#^Call to an undefined method FFI\|object#'
23 changes: 0 additions & 23 deletions psalm.xml

This file was deleted.

1 change: 1 addition & 0 deletions src/Audio/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Serafim\SDL\Audio;

// @phpstan-ignore-next-line offsetAccess.nonOffsetAccessible
if (\unpack('S', "\x01\x00")[1] === 1) {
define('Serafim\SDL\Audio\AUDIO_U16SYS', 0x0010);
define('Serafim\SDL\Audio\AUDIO_S16SYS', 0x8010);
Expand Down
17 changes: 11 additions & 6 deletions src/SDL.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function __construct(
parent::__construct(\FFI::cdef((string) $header, $this->library));
}

private function getHeader(PreprocessorInterface $pre, ?CacheInterface $cache): string|\Stringable
private function getHeader(PreprocessorInterface $pre, ?CacheInterface $cache): \Stringable
{
if ($cache !== null) {
return new CacheAwareHeader($this->platform, $this->version, $pre, $cache);
Expand All @@ -151,17 +151,20 @@ private function getHeader(PreprocessorInterface $pre, ?CacheInterface $cache):
}

/**
* @param non-empty-string|null $library
* @return non-empty-string
*
* @psalm-suppress MoreSpecificReturnType
* @psalm-suppress LessSpecificReturnStatement
*/
private function detectLibraryPathname(?string $library): string
{
if ($library !== null) {
return \realpath($library) ?: Locator::resolve($library) ?? $library;
/**
* @var non-empty-string
* @phpstan-ignore-next-line ternary.shortNotAllowed
*/
return \realpath($library) ?: Locator::resolve($library) ?: $library;
}

/** @var non-empty-string */
return match ($this->platform) {
Platform::WINDOWS => Locator::resolve('SDL2.dll')
?? throw new \RuntimeException(<<<'error'
Expand All @@ -178,13 +181,15 @@ private function detectLibraryPathname(?string $library): string
Please make sure the SDL2 library is installed or specify
the path to the binary explicitly.
error),
// @phpstan-ignore-next-line match.alwaysTrue
Platform::DARWIN => Locator::resolve('libSDL2-2.0.0.dylib')
?? throw new \RuntimeException(<<<'error'
Could not load [libSDL2-2.0.0.dylib].
Please make sure the SDL2 library is installed or specify
the path to the binary explicitly.
error),
default => throw new \RuntimeException('Unknown platform'),
};
}

Expand All @@ -194,7 +199,7 @@ private function detectLibraryPathname(?string $library): string
private function detectVersion(): VersionInterface
{
/**
* @var object{SDL_GetVersion:callable(object):void} $ffi
* @var object{SDL_GetVersion:callable(object):void}|\FFI $ffi
*/
$ffi = \FFI::cdef(<<<'CLANG'
typedef uint8_t Uint8;
Expand Down

0 comments on commit d8599c7

Please sign in to comment.