Skip to content

Conversation

TomasVotruba
Copy link
Member

No description provided.

@samsonasik
Copy link
Member

samsonasik commented Sep 14, 2025

It looks similar to InlineArrayReturnAssignRector

final class InlineArrayReturnAssignRector extends AbstractRector

see https://getrector.com/rule-detail/inline-array-return-assign-rector

@TomasVotruba
Copy link
Member Author

Thanks 👍 I could not find this one. I'll extend it

@TomasVotruba TomasVotruba force-pushed the tv-array-assing-to-return branch from 8826594 to 94924c8 Compare September 14, 2025 19:26
@TomasVotruba TomasVotruba force-pushed the tv-array-assing-to-return branch from cd8970e to 68fb88b Compare September 14, 2025 22:16
@TomasVotruba TomasVotruba changed the title [code-quality] Kick off SoleArrayDimFetchAssignsToDirectNewArrayRector [code-quality] Improve InlineArrayReturnAssignRector to include implicit array instantiation and nested arrays Sep 14, 2025
@TomasVotruba TomasVotruba force-pushed the tv-array-assing-to-return branch 2 times, most recently from fb7b68e to ee3da33 Compare September 14, 2025 22:18
@TomasVotruba TomasVotruba enabled auto-merge (squash) September 14, 2025 22:19
@TomasVotruba TomasVotruba force-pushed the tv-array-assing-to-return branch 2 times, most recently from ef52b3b to 7d6a5b5 Compare September 14, 2025 22:22
@TomasVotruba TomasVotruba force-pushed the tv-array-assing-to-return branch from 7d6a5b5 to d74c298 Compare September 14, 2025 22:27
@TomasVotruba TomasVotruba force-pushed the tv-array-assing-to-return branch from d74c298 to c644034 Compare September 14, 2025 22:28
final class IncludeEmptyAssign
{
public function getPerson()
public function run($person2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when param named $person sshould be skipped

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed 👍 Could you handle it? I'm off soon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check if any regression if conflict with existing params

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasVotruba TomasVotruba merged commit a96c2d3 into main Sep 14, 2025
49 checks passed
@TomasVotruba TomasVotruba deleted the tv-array-assing-to-return branch September 14, 2025 22:36
@samsonasik
Copy link
Member

samsonasik commented Sep 14, 2025

There are many regression on this, eg: this should be skipped

     public function some(SomeObject $someObject): array
     {
-        $message = [
-           'type' => 'type'
-            'id' => (string) $someObject->getId(),
-        ];
-        $message['link'] = $this->getSome($someObject);

 -      return $message;
+        return ['link' => $this->getSome($fuelOrder)];
     }

Also, if there is an if before:

         $someVar[$variable] = (float) $data;
 
         if (rand(0, 1)) {
-            $someVar[sprintf('%', $type)] = 0.0;
-            $someVar[$type] = 0.0;
-
-            return $someVar;
+            return ['' => 0.0];
         }

also cause crash on UnaryMinus:

         "System error: "Not implemented yet. Go to "Rector\PhpParser\Node\NodeFactory::createArrayItem()" and add check
         for "PhpParser\Node\Expr\UnaryMinus" node."  

I will look into those :)

@samsonasik
Copy link
Member

The reason for complex append is invalid is because we don't know the variable is available before first variable as this PR cause not rely on initialization, that cause this invalid change:

         $someVar[$variable] = (float) $data;
 
         if (rand(0, 1)) {
-            $someVar[sprintf('%', $type)] = 0.0;
-            $someVar[$type] = 0.0;
-
-            return $someVar;
+            return ['' => 0.0];
         }

@samsonasik
Copy link
Member

@samsonasik
Copy link
Member

This dynamic key should also be skipped:

     public function create($variable, $type, $data)
     {
-        $someVar[sprintf('%', $type)] = 0.0;
-        $someVar[$type] = 0.0;
-
-        return $someVar;
+        return ['' => 0.0];

@samsonasik
Copy link
Member

@samsonasik
Copy link
Member

@samsonasik
Copy link
Member

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.

3 participants