Skip to content

Commit 1b89592

Browse files
authored
Use get_debug_type() instead of get_class() and gettype() (phpactor#2637)
1 parent d25db46 commit 1b89592

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

lib/CodeBuilder/Domain/Builder/AbstractBuilder.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Generator;
66
use RuntimeException;
7+
use function is_object;
8+
use function sprintf;
9+
use function get_debug_type;
710

811
abstract class AbstractBuilder implements Builder
912
{
@@ -60,7 +63,7 @@ public function children(): Generator
6063
throw new RuntimeException(sprintf(
6164
'Child "%s" is not a builder instance, it is a "%s"',
6265
$childName,
63-
is_object($child) ? get_class($child) : gettype($child)
66+
get_debug_type($child),
6467
));
6568
}
6669

lib/CodeBuilder/Domain/TemplatePathResolver/FilterPhpVersionDirectoryIterator.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
use FilterIterator;
77
use RuntimeException;
88
use SplFileInfo;
9+
use function get_debug_type;
10+
use function preg_match;
11+
use function sprintf;
12+
use function version_compare;
913

1014
class FilterPhpVersionDirectoryIterator extends FilterIterator
1115
{
@@ -25,7 +29,7 @@ public function accept(): bool
2529
throw new RuntimeException(
2630
sprintf(
2731
'Expected instance of "\SplFileInfo", got "%s".',
28-
\is_object($file) ? \get_class($file) : \gettype($file)
32+
get_debug_type($file)
2933
)
3034
);
3135
}

lib/Extension/Core/Command/DebugContainerCommand.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Input\InputOption;
1111
use Symfony\Component\Console\Output\OutputInterface;
12+
use function get_debug_type;
1213

1314
class DebugContainerCommand extends Command
1415
{
@@ -53,12 +54,12 @@ private function renderServices(OutputInterface $output): Table
5354

5455
try {
5556
$value = $this->container->get($serviceId);
56-
$type = is_object($value) ? get_class($value) : gettype($value);
57+
$type = get_debug_type($value);
5758
} catch (RuntimeException $exception) {
5859
$table->addRow(['<error>Error: '.$serviceId.'</>', $exception->getMessage()]);
5960
}
6061

61-
$table->addRow([$serviceId, $type ]);
62+
$table->addRow([$serviceId, $type]);
6263
}
6364
$table->render();
6465
return $table;

lib/Extension/LanguageServer/LanguageServerExtension.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@
7373
use Psr\Log\LoggerInterface;
7474
use RuntimeException;
7575
use Webmozart\Assert\Assert;
76+
use function array_filter;
77+
use function array_keys;
78+
use function array_values;
79+
use function get_debug_type;
80+
use function implode;
81+
use function is_string;
82+
use function sprintf;
7683

7784
class LanguageServerExtension implements Extension
7885
{
@@ -336,7 +343,7 @@ private function registerServiceManager(ContainerBuilder $container): void
336343
throw new RuntimeException(sprintf(
337344
'Tagged service provider "%s" does not implement ServiceProvider interface, is a "%s"',
338345
$serviceId,
339-
is_object($provider) ? get_class($provider) : gettype($provider)
346+
get_debug_type($provider),
340347
));
341348
}
342349
$providers[] = $provider;

lib/WorseReflection/Core/Name.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
namespace Phpactor\WorseReflection\Core;
44

55
use InvalidArgumentException;
6+
use function explode;
7+
use function get_debug_type;
8+
use function implode;
9+
use function sprintf;
10+
use function str_starts_with;
11+
use function trim;
612

713
class Name
814
{
@@ -46,7 +52,7 @@ public static function fromUnknown($value): Name
4652
/** @phpstan-ignore-next-line */
4753
throw new InvalidArgumentException(sprintf(
4854
'Do not know how to create class from type "%s"',
49-
is_object($value) ? get_class($value) : gettype($value)
55+
get_debug_type($value)
5056
));
5157
}
5258

0 commit comments

Comments
 (0)