Skip to content

Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector doesn't respect the interface #2696

@Aerendir

Description

@Aerendir
Subject Details
Rector version 0.6.10
PHP version PHP 7.2

Current Behaviour

1) src/Email/Email.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -42,7 +42,7 @@
      * @throws \InvalidArgumentException
      * @throws StringsException
      */
-    public function __construct($value)
+    public function __construct(string $value)
     {
         $validator = new EmailValidator();
    ----------- end diff -----------

Applied rules:

 * Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector
 * Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
 * Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector
 * Rector\Rector\Argument\ArgumentRemoverRector
 * Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector
 * Rector\CodeQuality\Rector\If_\RemoveAlwaysTrueConditionSetInConstructorRector
 * Rector\DeadCode\Rector\ClassMethod\RemoveOverriddenValuesRector
 * Rector\DeadCode\Rector\FunctionLike\RemoveCodeAfterReturnRector

The class Email inherits from a generic interface with this signature:

interface SimpleValueObjectInterface extends ValueObjectInterface
{
    /**
     * Accepts a simple scalar value.
     *
     * @param mixed $value
     */
    public function __construct($value);
}

Adding the type hint string causes the code to break.

I'm going to write a failing test case for this.

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