Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeDeclaration] Add AddReturnArrayDocblockBasedOnArrayMapRector #6235

Merged
merged 7 commits into from
Aug 14, 2024

Conversation

TomasVotruba
Copy link
Member

No description provided.

@samsonasik
Copy link
Member

I actually still working on it similar to it at PR:

@samsonasik
Copy link
Member

Oh, I see, it on return instead of param ...

@TomasVotruba
Copy link
Member Author

@samsonasik Indeed :D I came across different but very similar case, so I'm trying to cover it

@TomasVotruba TomasVotruba force-pushed the tv-return-array-filter branch 3 times, most recently from 09b96ff to 99c28fd Compare August 14, 2024 16:53
@samsonasik
Copy link
Member

samsonasik commented Aug 14, 2024

new fixture is needed to not change already valid docblock with valid class name from use statement:

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddReturnArrayDocblockBasedOnArrayMapRector\Fixture;

use stdClass;

final class SkipAlreadyValidArrayClassNameReturn
{
    /**
     * @return stdClass[]
     */
    public function process(array $items)
    {
        return array_map(function ($item): stdClass {
            return $item;
        }, $items);
    }
}

@TomasVotruba TomasVotruba force-pushed the tv-return-array-filter branch 2 times, most recently from 83c47fb to e0e4083 Compare August 14, 2024 17:03
@samsonasik
Copy link
Member

new fixture for union return is needed:

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddReturnArrayDocblockBasedOnArrayMapRector\Fixture;

final class UnionReturnMap
{
+   /**
+    * @return float[]|int[]
+    */
    public function run(array $items)
    {
        if (mt_rand(0, 1)) {
            return array_map(function ($item): float {
                return $item;
            }, $items);
        }

        return array_map(function ($item): int {
            return 1000;
        }, $items);
    }
}

@TomasVotruba
Copy link
Member Author

Done 👍

@TomasVotruba
Copy link
Member Author

Let's ship this 👍

@TomasVotruba TomasVotruba merged commit 3ed476b into main Aug 14, 2024
35 checks passed
@TomasVotruba TomasVotruba deleted the tv-return-array-filter branch August 14, 2024 22:26
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.

2 participants