Rector: Asssert\Choice callback

Created on 3 Jan 2020  路  4Comments  路  Source: rectorphp/rector

| Subject | Details |
| :------------- | :----------------------------------------------------------- |
| Rector version |v0.6.4
| PHP version | php7.4
| Full Command | vendor/bin/rector process src --set symfony40

Current Behaviour

Command breaks with following error:

````
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints\AssertChoiceTagValueNode::__construct() must be of the type array or null, string given, called in /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php on line 39 and defined in /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php:35
Stack trace:

0 /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php(39): Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints\AssertChoiceTagValueNode->__construct('getValidManualT...', true, '(callback="getV...')

1 /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocParse in /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php on line 35

Fatal error: Uncaught TypeError: Argument 1 passed to Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints\AssertChoiceTagValueNode::__construct() must be of the type array or null, string given, called in /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php on line 39 and defined in /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php:35
Stack trace:

0 /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php(39): Rector\BetterPhpDocParser\PhpDocNode\Symfony\Validator\Constraints\AssertChoiceTagValueNode->__construct('getValidManualT...', true, '(callback="getV...')

1 /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocParse in /Users/peterrehm/code/php/project/vendor/rector/rector/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php on line 35

````

It seems it cannot handle the Assert\Choice callback:

````php

class Activity
{
/**
* @var string
*
* @ORM\Column(name="contact_type", type="string", length=255)
* @Assert\Choice(callback="getValidManualTypes", strict=true)
* @Assert\NotBlank()
*/
private $contactType;

public static function getValidManualTypes() : array
{
    return array(
        'customer.activity.types.PHONE' => self::TYPE_PHONE,
        'customer.activity.types.EMAIL' => self::TYPE_EMAIL,
        'customer.activity.types.CORRESPONDENCE' => self::TYPE_CORRESPONDENCE,
        'customer.activity.types.VISIT' => self::TYPE_VISIT,
        'customer.activity.types.NOTE' => self::TYPE_NOTE
    );
}

}
````

Expected Behaviour

It should not break with the exception.

bug

All 4 comments

Hi, thanks for reporting. I'll look on it

Thanks for the awesome support. 馃槏

This is wild. I just started playing with Rector a few hours ago. I came up with this same error and started looking for a fix... only to find it was reported and solved less than 4 hours ago!

@craigh Well, this was as an easy pick, just adding a string type into docblock:
https://github.com/rectorphp/rector/pull/2547/files#diff-e132ef862a5f2592730c29b30b509e86R35

Usually it takes longer :D but thanks :heart: I try to fix issues quickly, so people can enjoy migrating

Was this page helpful?
0 / 5 - 0 ratings