From 236ecdc0a2042de92d4cc98e1d0e6b281f2e159a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 26 Sep 2023 14:36:04 +0200 Subject: [PATCH] fixed parser [Closes #28] --- src/RobotLoader/RobotLoader.php | 4 ++-- tests/Loaders/RobotLoader.phpt | 2 ++ tests/Loaders/file/bug-28.php | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/Loaders/file/bug-28.php diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 9fa4257..deccf42 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -373,9 +373,9 @@ private function scanPhp(string $file): array $expected = null; } - if ($token->text === '{') { + if ($token->id === ord('{')) { $level++; - } elseif ($token->text === '}') { + } elseif ($token->id === ord('}')) { $level--; } } diff --git a/tests/Loaders/RobotLoader.phpt b/tests/Loaders/RobotLoader.phpt index 1139830..a23e99a 100644 --- a/tests/Loaders/RobotLoader.phpt +++ b/tests/Loaders/RobotLoader.phpt @@ -20,6 +20,7 @@ $loader->addDirectory(__DIR__ . '/files/'); // purposely doubled $loader->addDirectory(__DIR__ . '/file/interface.php'); // as file $loader->addDirectory(__DIR__ . '/file/class.const.php'); $loader->addDirectory(__DIR__ . '/file/trait.php'); +$loader->addDirectory(__DIR__ . '/file/bug-28.php'); $loader->excludeDirectory(__DIR__ . '/files/exclude'); $loader->excludeDirectory(__DIR__ . '/files/exclude2/excluded.php'); $loader->register(); @@ -27,6 +28,7 @@ $loader->register(); Assert::false(class_exists('ConditionalClass')); // files/conditional.class.php Assert::true(interface_exists('TestInterface')); // file/interface.php Assert::true(trait_exists('TestTrait')); // file/trait.php +Assert::true(class_exists('Bug28')); // file/bug-28.php Assert::true(class_exists('TestClass')); // files/namespaces1.php Assert::true(class_exists('MySpace1\TestClass1')); // files/namespaces1.php diff --git a/tests/Loaders/file/bug-28.php b/tests/Loaders/file/bug-28.php new file mode 100644 index 0000000..ec25211 --- /dev/null +++ b/tests/Loaders/file/bug-28.php @@ -0,0 +1,13 @@ +