Skip to content

Add SimpleScope PHPStan-free type resolution proof of concept - #8463

Draft
TomasVotruba wants to merge 8 commits into
mainfrom
simple-scope-tier3-poc
Draft

Add SimpleScope PHPStan-free type resolution proof of concept#8463
TomasVotruba wants to merge 8 commits into
mainfrom
simple-scope-tier3-poc

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

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 + concrete StringType, IntegerType, BooleanType, NullType, ArrayType, ObjectType, MixedType
  • Rector\SimpleScope\SimpleScope - resolves an expression to a SimpleType (literals, new X, local variables)
  • Rector\SimpleScope\SimpleScopeResolver - builds a scope from parameters and local assignments, in source order
  • DemoObjectMethodCallRenameRector - a Tier-3 name-matcher rule that does its own type resolution with zero PHPStan usage in its logic

Scope and limits

  • Nothing existing is changed; this is a self-contained island.
  • Handles the local, syntactic cases (literals, 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 return MixedType (safe no-op).
  • Covered by a unit test for the resolver and fixture tests for the demo rule.

Passes composer complete-check and composer rector locally.

@TomasVotruba
TomasVotruba force-pushed the simple-scope-tier3-poc branch 2 times, most recently from a6773d3 to ede5d41 Compare September 5, 2026 12:56
@TomasVotruba
TomasVotruba marked this pull request as draft September 6, 2026 06:39
@TomasVotruba
TomasVotruba force-pushed the simple-scope-tier3-poc branch from 2579989 to c4ee891 Compare September 6, 2026 07:17
TomasVotruba and others added 4 commits September 6, 2026 19:17
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.
@TomasVotruba
TomasVotruba force-pushed the simple-scope-tier3-poc branch from 516f073 to 4d03fc7 Compare September 6, 2026 17:18
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants