feat: implement addItemToReturnArray method#69
Conversation
|
It inherits from this commit: #64 |
Coverage Report for CI Build 27781083233Coverage increased (+0.2%) to 98.871%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b3b724c1f4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
b3b724c to
2d7ffe6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d7ffe63e6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3fadeec638
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| protected function parsePHPCode(string $code): array | ||
| { | ||
| try { | ||
| $stmts = new ParserFactory()->createForHostVersion()->parse("<?php\n{$code};"); |
There was a problem hiding this comment.
Reject statements before embedding array values
When addItemToReturnArray() is called with syntactically valid PHP that is not a single expression, such as return 1 or $a = 1; $b = 2, this parser accepts it here and PreformattedExpression later prints the raw text inside an array item. That produces invalid generated PHP like return [return 1,]; instead of throwing InvalidPHPCodeException, so callers can corrupt the target file with an input that passed validation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Validate PHP syntax only. Semantic correctness of the value is the caller's responsibility, like elsewhere in this library.
3fadeec to
cf924f2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf924f2562
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
💡 Codex ReviewWhen the target method contains a closure or anonymous function before its own returned array, ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca7af3fd92
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| protected function validatePHPCode(string $code): void | ||
| { | ||
| try { | ||
| new ParserFactory()->createForHostVersion()->parse("<?php\n{$code}?>"); |
There was a problem hiding this comment.
Reject statements before embedding expressions
When $value or $key is a syntactically valid PHP statement but not an expression (for example return 1; or if ($x) {}), this validation succeeds because it parses the snippet as a whole PHP file. The same raw text is then printed inside an array item expression by AddItemToReturnArray, producing an invalid PHP file instead of throwing InvalidPHPCodeException; validate these snippets specifically as expressions before accepting them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 58b0487bcd
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| case First = 'first'; | ||
| case Second = 'second'; |
There was a problem hiding this comment.
Declare the test enum as backed before assigning values
Because this remains enum SomeEnum rather than enum SomeEnum: string, adding scalar case values makes the file fatal when PHP loads or lints it (Case First of non-backed enum ... must not have a value). The enum-related fixtures generated from this file are now invalid PHP, so add : string or keep unit cases before relying on these tests.
Useful? React with 👍 / 👎.
| && !empty($item->key) | ||
| && $printer->prettyPrintExpr($item->key) === $this->keyExpr->value | ||
| ) { | ||
| $item->value = $this->valueExpr; |
There was a problem hiding this comment.
Reset by-reference flags when replacing array items
If the existing return array contains a keyed by-reference item, e.g. 'role' => &$role, this replacement leaves the original ArrayItem::$byRef flag set while swapping in the new preformatted expression. The printer will then emit invalid PHP such as 'role' => &'admin', so updating a valid return array can corrupt the file; reset byRef or replace the whole ArrayItem when changing the value.
Useful? React with 👍 / 👎.
refs: #71