Skip to content

Commit

Permalink
readable paths in closures
Browse files Browse the repository at this point in the history
  • Loading branch information
mindplay-dk committed Dec 5, 2023
1 parent 8482ea9 commit 917aa44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/readable.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function value(mixed $value): string
if ($value instanceof Closure) {
$reflection = new ReflectionFunction($value);

return "{Closure in " . $reflection->getFileName() . "({$reflection->getStartLine()})}";
return "{Closure in " . self::path($reflection->getFileName()) . "({$reflection->getStartLine()})}";
}

return "{" . ($value instanceof \stdClass ? "object" : get_class($value)) . "}";
Expand Down
4 changes: 2 additions & 2 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function () {
eq(readable::value($file), '{stream}');
eq(readable::value([new TestClass(), 'instanceMethod']), '{TestClass}->instanceMethod()');
eq(readable::value(['TestClass', 'staticMethod']), 'TestClass::staticMethod()');
eq(readable::value(empty_closure()), '{Closure in ' . __DIR__ . DIRECTORY_SEPARATOR . 'fixtures.php(22)}');
eq(readable::value(empty_closure()), '{Closure in test/fixtures.php(22)}');
eq(readable::value(new InvokableTestClass()), '{InvokableTestClass}');
eq(readable::value($unknown), '{unknown type}');

Expand All @@ -57,7 +57,7 @@ function () {
eq(readable::callback(new InvokableTestClass()), '{InvokableTestClass}->__invoke()');
eq(readable::callback([new TestClass(), 'instanceMethod']), '{TestClass}->instanceMethod()');
eq(readable::callback(['TestClass', 'staticMethod']), 'TestClass::staticMethod()');
eq(readable::callback(empty_closure()), '{Closure in ' . __DIR__ . DIRECTORY_SEPARATOR . 'fixtures.php(22)}');
eq(readable::callback(empty_closure()), '{Closure in test/fixtures.php(22)}');
eq(readable::callback('is_array'), 'is_array()');

fclose($file);
Expand Down

0 comments on commit 917aa44

Please sign in to comment.