Skip to content

Commit

Permalink
Fix opis#70
Browse files Browse the repository at this point in the history
  • Loading branch information
and1truong committed Jul 24, 2020
1 parent dec9fc5 commit 9fee604
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ReflectionClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,22 @@ public function getCode()
$id_start_ci = strtolower($id_start);
$id_name = '';
$state = 'id_name';

if ($context === 'new') {
if ($id_start !== '\\' && !in_array($id_start_ci, $class_keywords)) {
if ($classes === null) {
$classes = $this->getClasses();
}

if (isset($classes[$id_start_ci])) {
$id_start = $classes[$id_start_ci];
}
if ($id_start[0] !== '\\') {
$id_start = $nsf . '\\' . $id_start;
}
}
}

break 2;
case T_VARIABLE:
$code .= $token[1];
Expand Down
13 changes: 13 additions & 0 deletions tests/ClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@
use Closure;
use stdClass;
use Serializable;
use Opis\Closure\ClosureContext;
use Opis\Closure\ReflectionClosure;
use Opis\Closure\SerializableClosure;

class ClosureTest extends \PHPUnit\Framework\TestCase
{
public function testClassNameWithUse()
{
$wrapper = new SerializableClosure(
function () {
return new ClosureContext; // new object without `()`
}
);

$code = $wrapper->getReflector()->getCode();
$this->assertStringContainsString('Opis\Closure\ClosureContext', $code);
}

protected function s($closure)
{
if($closure instanceof Closure)
Expand Down

0 comments on commit 9fee604

Please sign in to comment.