From 7e82a420fe89b1472cd3e9b0a3882a1792e6bcd4 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Sun, 20 Feb 2022 17:25:44 +0100 Subject: [PATCH] PHP8 - Utilize "get_debug_type" --- src/Fixer/Alias/RandomApiMigrationFixer.php | 2 +- .../ConstantNotation/NativeConstantInvocationFixer.php | 2 +- .../FunctionNotation/NativeFunctionInvocationFixer.php | 4 ++-- src/Runner/FileFilterIterator.php | 2 +- src/Tokenizer/Token.php | 10 +++------- tests/Fixer/Alias/RandomApiMigrationFixerTest.php | 2 +- .../NativeConstantInvocationFixerTest.php | 4 ++-- .../NativeFunctionInvocationFixerTest.php | 2 +- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Fixer/Alias/RandomApiMigrationFixer.php b/src/Fixer/Alias/RandomApiMigrationFixer.php index c8049913212..8b722819cc3 100644 --- a/src/Fixer/Alias/RandomApiMigrationFixer.php +++ b/src/Fixer/Alias/RandomApiMigrationFixer.php @@ -149,7 +149,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn throw new InvalidOptionsException(sprintf( 'Replacement for function "%s" must be a string, "%s" given.', $functionName, - \is_object($replacement) ? \get_class($replacement) : \gettype($replacement) + get_debug_type($replacement) )); } } diff --git a/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php b/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php index d14f7f5a1bd..c6828d6ff6a 100644 --- a/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php +++ b/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php @@ -206,7 +206,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn if (!\is_string($constantName) || '' === trim($constantName) || trim($constantName) !== $constantName) { throw new InvalidOptionsException(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', - \is_object($constantName) ? \get_class($constantName) : \gettype($constantName) + get_debug_type($constantName) )); } } diff --git a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php index f719968e5f1..7ccbbfa70a7 100644 --- a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php +++ b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php @@ -223,7 +223,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn if (!\is_string($functionName) || '' === trim($functionName) || trim($functionName) !== $functionName) { throw new InvalidOptionsException(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', - \is_object($functionName) ? \get_class($functionName) : \gettype($functionName) + get_debug_type($functionName) )); } } @@ -239,7 +239,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn if (!\is_string($functionName) || '' === trim($functionName) || trim($functionName) !== $functionName) { throw new InvalidOptionsException(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', - \is_object($functionName) ? \get_class($functionName) : \gettype($functionName) + get_debug_type($functionName) )); } diff --git a/src/Runner/FileFilterIterator.php b/src/Runner/FileFilterIterator.php index 7210b94e062..37486cb190a 100644 --- a/src/Runner/FileFilterIterator.php +++ b/src/Runner/FileFilterIterator.php @@ -61,7 +61,7 @@ public function accept(): bool throw new \RuntimeException( sprintf( 'Expected instance of "\SplFileInfo", got "%s".', - \is_object($file) ? \get_class($file) : \gettype($file) + get_debug_type($file) ) ); } diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index 8f94e90f26e..6cf45fe31a2 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -55,14 +55,14 @@ public function __construct($token) if (!\is_int($token[0])) { throw new \InvalidArgumentException(sprintf( 'Id must be an int, got "%s".', - \is_object($token[0]) ? \get_class($token[0]) : \gettype($token[0]) + get_debug_type($token[0]) )); } if (!\is_string($token[1])) { throw new \InvalidArgumentException(sprintf( 'Content must be a string, got "%s".', - \is_object($token[1]) ? \get_class($token[1]) : \gettype($token[1]) + get_debug_type($token[1]) )); } @@ -77,11 +77,7 @@ public function __construct($token) $this->isArray = false; $this->content = $token; } else { - throw new \InvalidArgumentException(sprintf( - 'Cannot recognize input value as valid Token prototype, got "%s".', - // @phpstan-ignore-next-line due to lack of strong typing of method parameter - \is_object($token) ? \get_class($token) : \gettype($token) - )); + throw new \InvalidArgumentException(sprintf('Cannot recognize input value as valid Token prototype, got "%s".', get_debug_type($token))); } } diff --git a/tests/Fixer/Alias/RandomApiMigrationFixerTest.php b/tests/Fixer/Alias/RandomApiMigrationFixerTest.php index a9a21dac7af..514c61931e9 100644 --- a/tests/Fixer/Alias/RandomApiMigrationFixerTest.php +++ b/tests/Fixer/Alias/RandomApiMigrationFixerTest.php @@ -38,7 +38,7 @@ public function testConfigureCheckSearchFunction(): void public function testConfigureCheckReplacementType(): void { $this->expectException(InvalidFixerConfigurationException::class); - $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "NULL" given\.$#'); + $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "null" given\.$#'); $this->fixer->configure(['replacements' => ['rand' => null]]); } diff --git a/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php b/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php index 9ca473f4449..32d1cd9105a 100644 --- a/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php +++ b/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php @@ -48,7 +48,7 @@ public function testConfigureRejectsInvalidExcludeConfigurationElement($element) $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', - \is_object($element) ? \get_class($element) : \gettype($element) + get_debug_type($element) )); $this->fixer->configure([ @@ -68,7 +68,7 @@ public function testConfigureRejectsInvalidIncludeConfigurationElement($element) $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', - \is_object($element) ? \get_class($element) : \gettype($element) + get_debug_type($element) )); $this->fixer->configure([ diff --git a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php index b8ccef8c3df..1c7c3524b9d 100644 --- a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php +++ b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php @@ -53,7 +53,7 @@ public function testConfigureRejectsInvalidConfigurationElement($element): void $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', - \is_object($element) ? \get_class($element) : \gettype($element) + get_debug_type($element) )); $this->fixer->configure([