Add SimpleScope PHPStan-free type resolution proof of concept - #8463
Open
TomasVotruba wants to merge 12 commits into
Open
Add SimpleScope PHPStan-free type resolution proof of concept#8463TomasVotruba wants to merge 12 commits into
TomasVotruba wants to merge 12 commits into
Conversation
TomasVotruba
force-pushed
the
simple-scope-tier3-poc
branch
2 times, most recently
from
September 5, 2026 12:56
a6773d3 to
ede5d41
Compare
TomasVotruba
marked this pull request as draft
September 6, 2026 06:39
TomasVotruba
force-pushed
the
simple-scope-tier3-poc
branch
2 times, most recently
from
September 6, 2026 17:18
516f073 to
4d03fc7
Compare
TomasVotruba
marked this pull request as ready for review
September 8, 2026 08:31
Introduce a standalone, dependency-free type layer as a first step toward reducing PHPStan coupling: - SimpleTypeInterface + concrete scalar/array/object/null/mixed types - SimpleScope resolves an expression to a SimpleType - SimpleScopeResolver builds a scope from params and local assigns - DemoObjectMethodCallRenameRector shows a Tier-3 name-matcher rule doing its own type resolution with zero PHPStan usage Nothing existing is changed; the island proves the model before any real rule migration.
…ependent reflection Renamed past the *.php.inc glob so the suite is green while the underlying order-dependent PHPStan reflection issue (stale single-file source locators across fastunit workers) is investigated. Reproduce with: vendor/bin/fastunit -p 4 tests rules-tests utils/phpstan/tests Restore by renaming back to fixture.php.inc once the root cause is fixed.
Group the PHPStan-free scope and type resolution under src/Analyzer:
- Rector\Analyzer\SimpleScope\{SimpleScope,SimpleScopeResolver}
- Rector\Analyzer\SimpleType\* (+ Contract\SimpleTypeInterface)
Tests mirror the layout under tests/Analyzer.
…essibleCallsRector First real rule backed by the PHPStan-free SimpleScope: the Reflection caller type (ReflectionProperty/ReflectionMethod) is resolved from local new/assign and param typehints instead of PHPStan's isObjectType. Now subscribes to function-likes and resolves their scope; setAccessible calls outside any function body are no longer targeted (rare, and safe to leave as a no-op on PHP 8.1+). Unresolved callers stay MixedType, so nothing is removed unless the type is certain - no false positives.
…ionSetAccessibleCallsRector Positive (type resolved -> removed): typed param, standalone function, closure. Skip (unresolved/non-matching -> untouched): untyped param (mixed), non-Reflection object, method-call caller (SimpleScope cannot infer return type - safe no-op).
…), add variadic isInstanceOf() - SimpleTypeInterface is now a marker (no describe()) - ObjectType exposes only isInstanceOf(string ...$classNames), exact match - rules use isInstanceOf() instead of getClassName() comparisons - unit test asserts by concrete type instead of describe()
… it at Expression level
- SimpleScopeNodeVisitor (DecoratingNodeVisitorInterface) resolves a SimpleScope
per function-like and attaches it to inner statements via AttributeKey::SIMPLE_SCOPE
- RemoveReflectionSetAccessibleCallsRector subscribes to Expression again and reads
the attached scope (no in-rule attribute writing, per rector-rules)
- SimpleScope::isObjectType(Expr, string ...) folds getType + instanceof + isInstanceOf
- add fixture covering setAccessible() nested in an if () {} block
… unit test The demo rule was only a scaffold; the real RemoveReflectionSetAccessibleCallsRector now exercises SimpleScope. Add an isObjectType() test so the method stays covered.
TomasVotruba
force-pushed
the
simple-scope-tier3-poc
branch
from
September 8, 2026 08:32
8e365b1 to
364dd06
Compare
…via native is_a Exact match still wins first (works for non-autoloadable fixture classes); for autoloadable classes, native is_a($class, $expected, true) resolves parent and interface relationships - PHPStan-free. Unlocks Tier-3 rules that match an interface or base class, not just leaf classes.
…sInstanceOf is_a($class, $parent, true) autoloads the class, unwanted in a static tool. The autoload-free alternatives (class_parents/class_implements) are banned by rector-rules in favor of ReflectionProvider - i.e. PHPStan, which is what this layer avoids. Static parent/interface resolution therefore needs its own source reflection; until then isInstanceOf stays exact-match only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
First concrete step toward reducing PHPStan coupling in the codebase. PHPStan is currently a runtime dependency used across ~545 source files (type system, scope, reflection, phpdoc parser). This PR does not remove any of that - it proves a model for a dependency-free type layer on an isolated island, so we can evaluate the approach before touching real rules.
What
A standalone, PHPStan-free type-resolution layer:
Rector\SimpleType\Contract\SimpleTypeInterface+ concreteStringType,IntegerType,BooleanType,NullType,ArrayType,ObjectType,MixedTypeRector\SimpleScope\SimpleScope- resolves an expression to aSimpleType(literals,new X, local variables)Rector\SimpleScope\SimpleScopeResolver- builds a scope from parameters and local assignments, in source orderDemoObjectMethodCallRenameRector- a Tier-3 name-matcher rule that does its own type resolution with zero PHPStan usage in its logicScope and limits
new, typed params, local vars). Cross-file inference (method return types, property types, flow-sensitive unions) still needs real reflection and is intentionally out of scope - those returnMixedType(safe no-op).Passes
composer complete-checkandcomposer rectorlocally.