Skip to content

ParamTypeDeclarationRector applying one of two types #2274

@orklah

Description

@orklah
Subject Details
Rector version v0.5.19
PHP version PHP 7.3
Full Command vendor\bin\rector.bat process FFI --config rector.yaml

Current Behaviour

I'm not done with the issue analysis yet, but I make the issue now. I will complete it later with more info and a PR if needed.

I have a file like this:

namespace {
    class FFI{
        /**
         * Returns size of C data type of the given FFI\CData or FFI\CType.
         *
         * @param CData|CType $pointer
         * @return int
         */
        public static function sizeof(&$pointer): int {}
    }
}

When I apply rector, it become:

namespace {
    class FFI{
        /**
         * Returns size of C data type of the given FFI\CData or FFI\CType.
         *
         * @param CData|CType $pointer
         * @return int
         */
        public static function sizeof(\CData &$pointer): int {}
    }
}

It seems it choose one of the type and added it to the signature, It shouldn't do that (I checked, the two classes don't have a common parent)

Here is the complete log with --debug:


C:\Users\username\PhpstormProjects\phpstorm-stubs>vendor\bin\rector.bat process FFI --config rector.yaml --debug
Rector v0.5.19
Config file: C:\Users\username\PhpstormProjects\phpstorm-stubs\rector.yaml

[parsing] FFI/FFI.php

./FFI/FFI.php required for FFI

./FFI/FFI.php required for FFI
[refactoring] FFI/FFI.php
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
[printing] FFI/FFI.php


1 file with changes
===================

1) FFI/FFI.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -182,7 +182,7 @@
          * @param CData|CType $pointer
          * @return int
          */
-        public static function sizeof(&$pointer): int {}
+        public static function sizeof(\CData &$pointer): int {}

         /**
          * Returns size of C data type of the given FFI\CData or FFI\CType.
@@ -190,7 +190,7 @@
          * @param CData|CType $pointer
          * @return int
          */
-        public static function alignof(&$pointer): int {}
+        public static function alignof(\CData &$pointer): int {}

         /**
          * Copies $size bytes from memory area $source to memory area $target.
    ----------- end diff -----------

Applied rectors:

 * Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector


                                                                                                                        
 [OK] Rector is done! 1 changed files                                                                                   
                                                                                                                        



Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions