Skip to content

Skip EntityNotFinalRule when native lazy objects or lazy ghost objects are enabled#724

Merged
ondrejmirtes merged 3 commits into2.0.xfrom
claude/issue-667-regression-test-yubNh
Feb 18, 2026
Merged

Skip EntityNotFinalRule when native lazy objects or lazy ghost objects are enabled#724
ondrejmirtes merged 3 commits into2.0.xfrom
claude/issue-667-regression-test-yubNh

Conversation

@ondrejmirtes
Copy link
Member

When Doctrine ORM is configured with lazy ghost objects (ORM 2.x) or
native lazy objects (ORM 3.4+), final entities no longer cause problems
because proxy subclasses are not needed. This detects the configuration
from the object manager and suppresses the error accordingly.

Fixes #667

https://claude.ai/code/session_01EHwDbWjcx526ofXQu1KxNz

@ruudk
Copy link
Contributor

ruudk commented Feb 18, 2026

@ondrejmirtes The shared claude.ai link cannot be opened by anyone but you. Not sure if you are aware. Thanks for fixing it though!

@ondrejmirtes
Copy link
Member Author

Yeah, needs to be polished and finished though 😊

My main motivation was that I wanted to mention this at https://github.com/phpstan/phpstan/blob/2.2.x/website/errors/doctrine.finalEntity.md / https://phpstan.org/error-identifiers/doctrine.finalEntity and realized it's not fixed yet.

…s are enabled

When Doctrine ORM is configured with lazy ghost objects (ORM 2.x) or
native lazy objects (ORM 3.4+), final entities no longer cause problems
because proxy subclasses are not needed. This detects the configuration
from the object manager and suppresses the error accordingly.

Fixes #667

https://claude.ai/code/session_01EHwDbWjcx526ofXQu1KxNz
@ondrejmirtes ondrejmirtes force-pushed the claude/issue-667-regression-test-yubNh branch from d645e3c to 892243b Compare February 18, 2026 09:52
@ondrejmirtes
Copy link
Member Author

@phpstan-bot Look at the CI bulld failures.
The pre-existing test for this rule needs to assert no errors based on the same conditions.
There can’t be local ignores but the errors need to be added to phpstan-baseline-orm-3.neon
The newly added test needs to be skipped if the right conditions are not met

And please skip the lazy ghost feature for ORM 2.x. Only keep the native lazy objects for new PHP and Doctrine3.x.

@phpstan-bot
Copy link

phpstan-bot commented Feb 18, 2026

Claude finished @ondrejmirtes's task in 10m 21s —— View job


All tasks completed

  • Investigate CI build failures
  • Read current code changes and understand the implementation
  • Remove lazy ghost objects support for ORM 2.x — only keep native lazy objects for Doctrine 3.4+ / PHP 8.4+
  • Rewrite entity-manager file to use enableNativeLazyObjects(true) instead of setLazyGhostObjectEnabled(true)
  • Exclude entity-manager-lazy-ghost-objects.php from PHPStan analysis (matches existing entity-manager.php pattern)
  • Fix pre-existing testRule / testRuleWithoutObjectManagerLoader to conditionally expect no errors when native lazy objects are enabled by default
  • Skip testRuleWithNativeLazyObjects when PHP < 8.4 or ORM < 3.4
  • Commit and push changes

Summary of changes (commit 4edefa3):

ObjectMetadataResolver.php — Removed the isLazyGhostObjectEnabled() check. Now only checks isNativeLazyObjectsEnabled() (ORM 3.4+) for the object-manager path and the PHP_VERSION_ID >= 80400 && method_exists(Configuration::class, 'enableNativeLazyObjects') fallback.

entity-manager-lazy-ghost-objects.php — Changed setLazyGhostObjectEnabled(true)enableNativeLazyObjects(true). Removed all @phpstan-ignore inline comments.

phpstan.neon — Added entity-manager-lazy-ghost-objects.php to excludePaths (follows existing pattern for entity-manager.php).

EntityNotFinalRuleTest.php:

  • Split into separate data providers: ruleProvider (for testRule with entity-manager) and ruleWithoutObjectManagerLoaderProvider (for testRuleWithoutObjectManagerLoader without entity-manager) — each conditionally expects no error for FinalEntity when native lazy objects are the default
  • Renamed testRuleWithLazyGhostObjectstestRuleWithNativeLazyObjects with markTestSkipped when PHP_VERSION_ID < 80400 or enableNativeLazyObjects method doesn't exist
  • Added isNativeLazyObjectsDefault() helper that checks if a fresh Configuration defaults to native lazy objects enabled
    |

…M 3.4+

- Remove isLazyGhostObjectEnabled() check from ObjectMetadataResolver
- Use enableNativeLazyObjects(true) instead of setLazyGhostObjectEnabled(true)
- Skip native lazy objects test when PHP < 8.4 or ORM < 3.4
- Conditionally expect no errors in pre-existing tests when native lazy
  objects are the default
- Exclude entity-manager-lazy-ghost-objects.php from PHPStan analysis

Co-authored-by: Ondřej Mirtes <ondrejmirtes@users.noreply.github.com>
@ondrejmirtes
Copy link
Member Author

@phpstan-bot Please check the PHPStan build failures for each version. We will probably need to introduce a new conditional baseline file. There are failures for PHPStan on 7.4 through 8.4 because these run doctrine/orm 2.x.

PHPStan on 8.3 with Doctrine 3 has differenet failures which can be added to phpstan-baseline-orm-3.neon IMHO.

@phpstan-bot
Copy link

phpstan-bot commented Feb 18, 2026

Claude finished @ondrejmirtes's task in 4m 48s —— View job


All tasks completed

  • Check CI build failures across all PHP versions
  • Analyze failures for PHP 7.4-8.4 (Doctrine ORM 2.x)
  • Analyze failures for PHP 8.3 with Doctrine 3
  • Fix @phpstan-ignore comments in source files to cover both ORM 2.x and 3.x identifiers
  • Handle method.notFound for isNativeLazyObjectsEnabled on ORM 2.x via conditional baseline
  • Commit and push fixes

Analysis

PHP 7.4–8.4 with ORM 2.x — 1 error each:

  • EntityNotFinalRuleTest.php:198method.notFound on Configuration::isNativeLazyObjectsEnabled() (method doesn't exist in ORM 2.x)

PHP 8.3 with Doctrine 3 — 6 errors, all function.alreadyNarrowedType:

  • ClassMetadataFactory.php:44method_exists($config, 'enableNativeLazyObjects')
  • ObjectMetadataResolver.php:77method_exists($config, 'isNativeLazyObjectsEnabled')
  • ObjectMetadataResolver.php:85method_exists(Configuration::class, 'enableNativeLazyObjects')
  • EntityNotFinalRuleTest.php:55,114,194method_exists(Configuration::class, ...)

Platform test (8.1 with ORM 3): Unrelated pre-existing failure (pgsql bool/null mismatch).

Summary of changes (commit 98b4890):

Source files (ClassMetadataFactory.php, ObjectMetadataResolver.php): Changed @phpstan-ignore function.impossibleType to @phpstan-ignore function.impossibleType, function.alreadyNarrowedType so both ORM 2.x and 3.x identifiers are covered. Added missing ignore on ObjectMetadataResolver.php:85.

EntityNotFinalRuleTest.php: Added @phpstan-ignore function.impossibleType, function.alreadyNarrowedType to the three method_exists() checks (lines 55, 114, 194).

phpstan-baseline-orm-2.neon (new): Baseline for the method.notFound error on Configuration::isNativeLazyObjectsEnabled() which only exists in ORM 3.4+.

compatibility/orm-3-baseline.php: Extended to conditionally include phpstan-baseline-orm-2.neon when ORM 3 is not installed (else branch).
·

- Add function.alreadyNarrowedType to @phpstan-ignore comments alongside
  function.impossibleType so both ORM 2.x and 3.x identifiers are covered
- Create phpstan-baseline-orm-2.neon for the method.notFound error on
  Configuration::isNativeLazyObjectsEnabled() which only exists in ORM 3.4+
- Extend compatibility/orm-3-baseline.php to conditionally include the
  ORM 2 baseline when ORM 3 is not installed

Co-authored-by: Ondřej Mirtes <ondrejmirtes@users.noreply.github.com>
@ondrejmirtes ondrejmirtes merged commit 734ef36 into 2.0.x Feb 18, 2026
39 of 40 checks passed
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.

Allow EntityNotFinalRule to be turned off when on Doctrine ORM 3.4 + PHP 8.4

4 participants

Comments