1
0
mirror of https://github.com/rectorphp/rector.git synced 2025-03-20 07:19:47 +01:00

Merge pull request from rectorphp/fixes

Fixes + bump to Symplify 4.6
This commit is contained in:
Tomáš Votruba 2018-08-03 08:49:32 +02:00 committed by GitHub
commit 9abf14f558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 100 deletions

@ -18,16 +18,16 @@
"symfony/console": "^3.4|^4.0",
"symfony/dependency-injection": "^3.4|^4.0",
"symfony/finder": "^3.4|^4.0",
"symplify/better-phpdoc-parser": "^4.5",
"symplify/changelog-linker": "^4.5",
"symplify/monorepo-builder": "^4.5"
"symplify/better-phpdoc-parser": "^4.6",
"symplify/changelog-linker": "^4.6",
"symplify/monorepo-builder": "^4.6"
},
"require-dev": {
"humbug/php-scoper": "^0.8.1",
"phpstan/phpstan": "^0.10.2",
"phpunit/phpunit": "^7.1",
"slam/php-cs-fixer-extensions": "^1.15",
"symplify/easy-coding-standard": "^4.5.1",
"symplify/easy-coding-standard": "^4.6",
"tracy/tracy": "^2.4"
},
"autoload": {
@ -63,8 +63,7 @@
"Rector\\YamlRector\\Tests\\": "packages/YamlRector/tests"
},
"classmap": [
"packages/Symfony/tests",
"tests"
"packages/Symfony/tests"
]
},
"scripts": {

@ -1,8 +1,5 @@
imports:
# in monorepo
- { resource: '../../../../vendor/symplify/better-phpdoc-parser/src/config/services.yml', ignore_errors: true }
# as dependency
- { resource: '../../../../../../symplify/better-phpdoc-parser/src/config/services.yml', ignore_errors: true }
- { resource: '%vendor%/symplify/better-phpdoc-parser/src/config/services.yml' }
services:
Rector\BetterPhpDocParser\:

@ -45,6 +45,7 @@ parameters:
# subtype
- '#Property PhpParser\\Node\\Param::\$type \(PhpParser\\Node\\Name|PhpParser\\Node\\NullableType\|string\|null\) does not accept PhpParser\\Node\\Identifier|PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType#' # 3
- '#Parameter \#1 \$containerBuilder of method Symplify\\EasyCodingStandard\\DependencyInjection\\DelegatingLoaderFactory::createFromContainerBuilderAndKernel\(\) expects Symfony\\Component\\DependencyInjection\\ContainerBuilder, Symfony\\Component\\DependencyInjection\\ContainerInterface given#' # 1
# false positive
- '#Parameter \#1 \$kernelClass of method Rector\\Symfony\\Bridge\\SymfonyKernelParameterGuard::(ensureKernelClassExists|ensureIsKernelInstance)\(\) expects string, string\|null given#' # 2
@ -72,6 +73,9 @@ parameters:
- '#Constructor of class [\s\S]+ has an unused parameter \$html#' # 2
- '#Call to an undefined method Nette\\Utils\\Html::add\(\)#' # 1
# A test class
- '#Class SomeClass not found#'
excludes_analyse:
# test files
- '*tests/Rector/Dynamic/MethodNameReplacerRector/**/SomeClass.php'

@ -1,64 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\DependencyInjection\CompilerPass;
use Nette\Utils\Strings;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
/**
* Bind parameters by default:
* - from "%value_name%"
* - to "$valueName"
*/
final class AutoBindParametersCompilerPass extends AbstractRecursivePass
{
public function process(ContainerBuilder $containerBuilder): void
{
$boundArguments = $this->createBoundArgumentsFromParameterBag($containerBuilder->getParameterBag());
foreach ($containerBuilder->getDefinitions() as $definition) {
// config binding has priority over default one
$bindings = array_merge($definition->getBindings(), $boundArguments);
$definition->setBindings($bindings);
}
}
/**
* @return BoundArgument[]
*/
private function createBoundArgumentsFromParameterBag(ParameterBagInterface $parameterBag): array
{
$boundArguments = [];
foreach ($parameterBag->all() as $name => $value) {
// skip system
if (Strings::startsWith($name, 'kernel.')) {
continue;
}
$parameterGuess = '$' . $this->undescoredToCamelCase($name);
$boundArgument = new BoundArgument($value);
// set used so it doesn't end on exceptions
[$value, $identifier, $isUsed] = $boundArgument->getValues();
$boundArgument->setValues([$value, $identifier, true]);
$boundArguments[$parameterGuess] = $boundArgument;
}
return $boundArguments;
}
/**
* @see https://stackoverflow.com/a/2792045/1348344
*/
private function undescoredToCamelCase(string $string): string
{
$string = str_replace('_', '', ucwords($string, '_'));
return lcfirst($string);
}
}

@ -1,20 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\DependencyInjection\CompilerPass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
final class AutowireDefaultCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $containerBuilder): void
{
foreach ($containerBuilder->getDefinitions() as $definition) {
if ($definition->getClass() === null) {
continue;
}
$definition->setAutowired(true);
}
}
}

@ -2,18 +2,21 @@
namespace Rector\DependencyInjection;
use Rector\DependencyInjection\CompilerPass\AutoBindParametersCompilerPass;
use Rector\DependencyInjection\CompilerPass\AutowireDefaultCompilerPass;
use Rector\DependencyInjection\CompilerPass\CollectorCompilerPass;
use Rector\NodeTypeResolver\DependencyInjection\CompilerPass\NodeTypeResolverCollectorCompilerPass;
use Rector\YamlRector\DependencyInjection\YamlRectorCollectorCompilerPass;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symplify\BetterPhpDocParser\DependencyInjection\CompilerPass\CollectDecoratorsToPhpDocInfoFactoryCompilerPass;
use Symplify\EasyCodingStandard\DependencyInjection\DelegatingLoaderFactory;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutoBindParametersCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireDefaultCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireSinglyImplementedCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\PublicForTestsCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\PublicDefaultCompilerPass;
final class RectorKernel extends Kernel
{
@ -65,14 +68,23 @@ final class RectorKernel extends Kernel
$containerBuilder->addCompilerPass(new YamlRectorCollectorCompilerPass());
$containerBuilder->addCompilerPass(new AutowireDefaultCompilerPass());
$containerBuilder->addCompilerPass(new NodeTypeResolverCollectorCompilerPass());
$containerBuilder->addCompilerPass(new AutowireSinglyImplementedCompilerPass());
// for symplify/better-php-doc-parser
$containerBuilder->addCompilerPass(new CollectDecoratorsToPhpDocInfoFactoryCompilerPass());
// for tests
$containerBuilder->addCompilerPass(new PublicForTestsCompilerPass());
// for defaults
$containerBuilder->addCompilerPass(new PublicDefaultCompilerPass());
$containerBuilder->addCompilerPass(new AutowireSinglyImplementedCompilerPass());
$containerBuilder->addCompilerPass(new AutoBindParametersCompilerPass());
}
/**
* This allows to use "%vendor%" variables in imports
* @param ContainerInterface|ContainerBuilder $container
*/
protected function getContainerLoader(ContainerInterface $container): DelegatingLoader
{
return (new DelegatingLoaderFactory())->createFromContainerBuilderAndKernel($container, $this);
}
}