Skip to content

Commit

Permalink
fixed parser [Closes #28]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 26, 2023
1 parent abc683f commit 236ecdc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/RobotLoader/RobotLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Loaders/RobotLoader.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ $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();

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
Expand Down
13 changes: 13 additions & 0 deletions tests/Loaders/file/bug-28.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

$foo = '';
$foo = "Hello {$foo}!";

class Bug28
{
public function fn()
{
}
}

0 comments on commit 236ecdc

Please sign in to comment.