Skip to content

Remove dead code and fix exception messages in legacy rules - #1042

Merged
mglaman merged 1 commit into
mainfrom
audit/1c2-legacy-cleanups
Sep 8, 2026
Merged

Remove dead code and fix exception messages in legacy rules#1042
mglaman merged 1 commit into
mainfrom
audit/1c2-legacy-cleanups

Conversation

@mglaman

@mglaman mglaman commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Part 4 of 9 in the legacy-code audit stack (on top of #1034). Dead code and exception-message cleanups surfaced by auditing the oldest code (2018–2019). No user-facing behavior changes and no release note needed.

What changed

  • Extension::parseInfo(): add the missing closing quote in the "Cannot read" exception message.
  • EntityFieldsViaMagicReflectionExtension: throw PHPStan's ShouldNotHappenException instead of a bare LogicException so the failure surfaces as an internal error with context.
  • PluginManagerSetsCacheBackendRule: return no errors instead of throwing when outside a class, and delete the $cacheKey block. That block computed the constant strings of the cache key argument and then did nothing with them; $hasCacheBackendSet was already true before its continue, so it was unreachable in effect.
  • DiscouragedFunctionsRule: drop 'eval'. It is a language construct, not a function, so it parses as Expr\Eval_ and never reached this rule's FuncCall check.

Out of scope

  • Whether PluginManagerSetsCacheBackendRule should require a literal cache key. The dead block looks like an abandoned attempt at that. This PR only removes the unreachable code and does not decide it.
  • Flagging eval at all. That needs a rule on Expr\Eval_, tracked separately if wanted.

Testing

Full suite, self-analysis, and phpcs are green.

🤖 Generated with Claude Code

- Extension::parseInfo(): add the missing closing quote in the exception
  message.
- EntityFieldsViaMagicReflectionExtension: throw PHPStan's
  ShouldNotHappenException instead of a bare LogicException so the failure
  surfaces as an internal error with context.
- PluginManagerSetsCacheBackendRule: return no errors instead of throwing
  when outside a class, and delete the $cacheKey block whose result was
  never read.
- DiscouragedFunctionsRule: drop 'eval'. It is a language construct and
  never parses as a function call, so the entry could never match.

No user-facing behavior changes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mglaman
mglaman force-pushed the audit/1c2-legacy-cleanups branch from ad6480b to 60f2868 Compare September 8, 2026 18:14
@mglaman
mglaman changed the base branch from audit/1c-latent-fixes to main September 8, 2026 18:15
@mglaman mglaman closed this Sep 8, 2026
@mglaman mglaman reopened this Sep 8, 2026
@mglaman
mglaman merged commit ba35837 into main Sep 8, 2026
19 of 20 checks passed
@mglaman
mglaman deleted the audit/1c2-legacy-cleanups branch September 9, 2026 14:55
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

Successfully merging this pull request may close these issues.

1 participant