Skip to content

Multiple import resources not working (last one overrides previous?) #2451

@lulco

Description

@lulco
Subject Details
Rector version 0.6.1
PHP version PHP 7.3
Full Command vendor/bin/rector process /var/www/my-app/app --autoload-file /var/www/my-app/app/bootstrap.php -vvv

Current Behaviour

I am trying to update my Nette 2.4 application to 3.0. This app uses package tomaj/nette-api. I wrote some rules for this package and store them into file tomaj-nette-api-1.x.x-2.0.0.yaml here is short sample:

services:    
    Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector:
        Tomaj\NetteApi\Handlers\ApiHandlerInterface:
            params: 'array'
            handle: 'Tomaj\NetteApi\Response\ResponseInterface'
    Rector\Rector\Typehint\ParentTypehintedArgumentRector:
        Tomaj\NetteApi\Handlers\ApiHandlerInterface:
            handle:
                $params: 'array'

Now I am trying to run rector with this config (rector.yaml):

imports:
    - { resource: tomaj-nette-api-1.x.x-2.0.0.yaml }
    - { resource: vendor/rector/rector/config/set/nette/nette-30.yaml }

I get no errors, but output is not as expected.

Minimal PHP Code Causing Issue

Before running rector:

<?php 

namespace App\Api\Handler;

use Tomaj\NetteApi\Handlers\BaseHandler;

class MyApiHandler extends BaseHandler
{
    public function handle($params)
    {
        // do something
    }
}

After running rector:

<?php 

namespace App\Api\Handler;

use Tomaj\NetteApi\Handlers\BaseHandler;

class MyApiHandler extends BaseHandler
{
    public function handle(array $params)
    {
        // do something
    }
}

Expected Behaviour

Output should be:

<?php
namespace App\Api\Handler;

use Tomaj\NetteApi\Response\ResponseInterface;
use Tomaj\NetteApi\Handlers\BaseHandler;

class MyApiHandler extends BaseHandler
{
    public function handle(array $params): ResponseInterface
    {
        // do something
    }
}

I have got this output when I run rector with this config:

imports:
    - { resource: tomaj-nette-api-1.x.x-2.0.0.yaml }
    # - { resource: vendor/rector/rector/config/set/nette/nette-30.yaml }

Just commented line with nette-30.yaml

I found the Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector section also in nette/* set so I think these rules somehow overrides my rules instead of merging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions