Skip to content

[TypeDeclaration] Split ParamTypeByMethodCallTypeRector into Object, Scalar and Array rules#8134

Merged
TomasVotruba merged 1 commit into
mainfrom
split-param-type-by-method-call-object-scalar
Jul 1, 2026
Merged

[TypeDeclaration] Split ParamTypeByMethodCallTypeRector into Object, Scalar and Array rules#8134
TomasVotruba merged 1 commit into
mainfrom
split-param-type-by-method-call-object-scalar

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jul 1, 2026

Copy link
Copy Markdown
Member

Why

ParamTypeByMethodCallTypeRector inferred every param type group at once (objects, scalars, arrays, unions). This splits it so each type group is owned by a focused, independently toggleable rule.

What

Shared engine extracted into AbstractParamTypeByMethodCallTypeRector (caller matching, guards, param loop). Each concrete rule narrows the change to a disjoint group via isMatchingParamType(). Types are null-stripped first, so nullable variants route to their own group.

Rule Owns Predicate
ObjectParamTypeByMethodCallTypeRector object types (incl. nullable) removeNull()->isObject()
ScalarParamTypeByMethodCallTypeRector string/int/float/bool removeNull()->isScalar()
ArrayParamTypeByMethodCallTypeRector array types (incl. nullable) removeNull()->isArray()
ParamTypeByMethodCallTypeRector (kept) remaining compound: cross-group unions (array|string), iterable, callable not object, scalar, nor array

Examples

ObjectParamTypeByMethodCallTypeRector

 final class UseDependency
 {
     public function __construct(private SomeTypedService $someTypedService) {}

-    public function go($value)
+    public function go(SomeObject $value)
     {
         $this->someTypedService->run($value); // run(SomeObject $object)
     }
 }

ScalarParamTypeByMethodCallTypeRector

 final class UseDependency
 {
     public function __construct(private SomeTypedService $someTypedService) {}

-    public function go($value)
+    public function go(string $value)
     {
         $this->someTypedService->run($value); // run(string $name)
     }
 }

ArrayParamTypeByMethodCallTypeRector

 final class UseDependency
 {
     public function __construct(private SomeTypedService $someTypedService) {}

-    public function go($value)
+    public function go(array $value)
     {
         $this->someTypedService->run($value); // run(array $values)
     }
 }

Notes

  • Existing scalar fixtures moved to the scalar rule test dir; pure-array fixtures to the array rule test dir; cross-group union fixtures stay with the old rule.
  • Redundant fixtures trimmed — kept one per unique dimension (node type / type shape) plus split-proof skips.
  • All four rules registered in TypeDeclarationLevel.

…Scalar and Array rules

Extract shared engine into AbstractParamTypeByMethodCallTypeRector; each concrete rule
owns a disjoint param type group via isMatchingParamType():

- ObjectParamTypeByMethodCallTypeRector - object types (incl. nullable)
- ScalarParamTypeByMethodCallTypeRector - scalar types (string/int/float/bool)
- ArrayParamTypeByMethodCallTypeRector  - array types (incl. nullable)
- ParamTypeByMethodCallTypeRector       - remaining compound (cross-group unions, iterable, callable)

Types are null-stripped first, so nullable variants route to their group.
@TomasVotruba TomasVotruba force-pushed the split-param-type-by-method-call-object-scalar branch from b046ca0 to 3142e04 Compare July 1, 2026 19:56
@TomasVotruba TomasVotruba changed the title [TypeDeclaration] Split ParamTypeByMethodCallTypeRector into Object and Scalar rules [TypeDeclaration] Split ParamTypeByMethodCallTypeRector into Object, Scalar and Array rules Jul 1, 2026
@TomasVotruba TomasVotruba merged commit 6b50c34 into main Jul 1, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the split-param-type-by-method-call-object-scalar branch July 1, 2026 20:02
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.

1 participant