report invalid array/param syntax in config [closes #983]

This commit is contained in:
Tomas Votruba 2019-02-07 09:16:59 +01:00
parent 91960dd621
commit aa1083882e
5 changed files with 13 additions and 9 deletions

View File

@ -23,6 +23,8 @@ final class OptionNameRectorTest extends AbstractRectorTestCase
*/
protected function getRectorConfiguration(): array
{
return [FormBuilder::class];
return [
'$formBuilderType' => FormBuilder::class
];
}
}

View File

@ -3,8 +3,10 @@
namespace Rector\DependencyInjection\Loader;
use Nette\Utils\Strings;
use Rector\Exception\Configuration\InvalidConfigurationException;
use ReflectionClass;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Yaml\Yaml;
/**
* Before:
@ -74,7 +76,12 @@ final class RectorServiceParametersShifter
// we can autowire exclusively 1 parameter only
if (count($arrayParameterNames) !== 1) {
continue;
throw new InvalidConfigurationException(sprintf(
'There must be array argument in "%s" constructor or explicit $argument name in configuration:%s%s',
$serviceName,
PHP_EOL . PHP_EOL,
Yaml::dump($serviceDefinition, Yaml::DUMP_OBJECT_AS_MAP)
));
}
$serviceDefinition['arguments']['$' . $arrayParameterNames[0]] = $nonReservedNonVariables;

View File

@ -2,11 +2,9 @@
namespace Rector\DependencyInjection;
use Rector\Contract\Rector\PhpRectorInterface;
use Rector\Contract\Rector\RectorInterface;
use Rector\DependencyInjection\CompilerPass\RemoveExcludedRectorsCompilerPass;
use Rector\DependencyInjection\Loader\TolerantRectorYamlFileLoader;
use Rector\FileSystemRector\Contract\FileSystemRectorInterface;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\GlobFileLoader;
use Symfony\Component\Config\Loader\LoaderInterface;

View File

@ -28,9 +28,6 @@ final class NewObjectToFactoryCreateRector extends AbstractRector
*/
public function __construct(array $objectToFactoryMethod)
{
dump($objectToFactoryMethod);
die;
$this->objectToFactoryMethod = $objectToFactoryMethod;
}
@ -65,7 +62,7 @@ CODE_SAMPLE
'MyClass' => [
'class' => 'MyClassFactory',
'method' => 'create',
]
],
]
),
]);

View File

@ -28,7 +28,7 @@ final class NewObjectToFactoryCreateRectorTest extends AbstractRectorTestCase
MyClass::class => [
'class' => MyClassFactory::class,
'method' => 'create',
]
],
];
}
}