Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreliable code extraction #12

Open
oruborus opened this issue Sep 15, 2024 · 0 comments
Open

Unreliable code extraction #12

oruborus opened this issue Sep 15, 2024 · 0 comments

Comments

@oruborus
Copy link
Contributor

When extracting code using the source text referred to by the reflection of the Closure, the following possibilities are not handled correctly:

  • a function surrounded by other function declarations on a single line
function ($notThisOne) {}; $funciton = function ($thisOne) {}; function ($notThisOneEither) {};
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "function ($notThisOne) {}"
  • an arrow function surrounded by other function declarations on a single line
function ($notThisOne) {}; $funciton = fn($thisOne) => null; function ($notThisOneEither) {};
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "function ($notThisOne) {}"
  • a static function surrounded by other function declarations on a single line
function ($notThisOne) {}; $funciton = static function ($thisOne) {}; function ($notThisOneEither) {};
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "function ($notThisOne) {}"
  • a static arrow function surrounded by other function declarations on a single line
function ($notThisOne) {}; $funciton = static fn($thisOne) => null; function ($notThisOneEither) {};
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "function ($notThisOne) {}"
  • more than one ignorable token between T_STATIC and T_FUNCTION
$function = static /* ignore me */ function ($thisOne) {};
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "function ($thisOne) {}", note the missing "static /* ignore me */ "
  • more than one ignorable token between T_STATIC and T_FN
$function = static /* ignore me */ fn($thisOne) => null;
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "fn($thisOne) => null", note the missing "static /* ignore me */ "
  • T_STATIC on a other line than T_FUNCTION
$function = static
function ($thisOne) {};
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "function ($thisOne) {}", note the missing "static "
  • T_STATIC on a other line than T_FN
$function = static
fn($thisOne) => null;
$rf = new ReflectionFunction($function);
$code = ClosureTransformer::getCode($rf); // "fn($thisOne) => null", note the missing "static "

I can tackle that issue if you want - but I'd like to add more tests to avoid regressions.

oruborus added a commit to oruborus/serializor that referenced this issue Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant