qa: include and use Rector

This commit is contained in:
Abdul Malik Ikhsan 2022-05-21 21:37:16 +07:00 committed by GitHub
parent 60a6656141
commit 5a50baed86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 119 additions and 41 deletions

1
.gitattributes vendored
View File

@ -12,5 +12,6 @@
/phpstan.neon.dist export-ignore
/psalm.xml export-ignore
/phpunit.xml.dist export-ignore
/rector.php export-ignore
*.stub linguist-language=PHP

View File

@ -47,11 +47,14 @@ jobs:
- uses: "ramsey/composer-install@v2"
- name: Running PHP Coding Standards Fixer
run: php vendor/bin/php-cs-fixer fix --dry-run
- name: Running PHPStan
run: php vendor/bin/phpstan
- name: Running Psalm
run: php vendor/bin/psalm
- name: Running PHP Coding Standards Fixer
run: php vendor/bin/php-cs-fixer fix --dry-run
- name: Running Rector
run: php vendor/bin/rector --dry-run

View File

@ -29,7 +29,8 @@
"friendsofphp/php-cs-fixer": "^3.4",
"marcocesarato/php-conventional-changelog": "^1.12",
"vimeo/psalm": "^4.18.1",
"mikey179/vfsstream": "^1.6.10"
"mikey179/vfsstream": "^1.6.10",
"rector/rector": "^0.12.23"
},
"autoload": {
"psr-4": {
@ -45,12 +46,14 @@
"scripts": {
"check": [
"phpunit",
"php-cs-fixer fix --dry-run",
"phpstan",
"psalm"
"psalm",
"php-cs-fixer fix --dry-run",
"rector --dry-run"
],
"fix": [
"php-cs-fixer fix"
"php-cs-fixer fix",
"rector"
],
"mutation": [
"@putenv XDEBUG_MODE=coverage",

62
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a62ba8b37c5f903b8ef7f737695c5008",
"content-hash": "d9ebcc2e5638317c0dbe69803a3d1522",
"packages": [
{
"name": "doctrine/annotations",
@ -2923,6 +2923,66 @@
},
"time": "2021-05-03T11:20:27+00:00"
},
{
"name": "rector/rector",
"version": "0.12.23",
"source": {
"type": "git",
"url": "https://github.com/rectorphp/rector.git",
"reference": "690b31768b322db886b35845f8452025eba2cacb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/rectorphp/rector/zipball/690b31768b322db886b35845f8452025eba2cacb",
"reference": "690b31768b322db886b35845f8452025eba2cacb",
"shasum": ""
},
"require": {
"php": "^7.2|^8.0",
"phpstan/phpstan": "^1.6"
},
"conflict": {
"phpstan/phpdoc-parser": "<1.2",
"rector/rector-cakephp": "*",
"rector/rector-doctrine": "*",
"rector/rector-laravel": "*",
"rector/rector-nette": "*",
"rector/rector-phpoffice": "*",
"rector/rector-phpunit": "*",
"rector/rector-prefixed": "*",
"rector/rector-symfony": "*"
},
"bin": [
"bin/rector"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "0.12-dev"
}
},
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Instant Upgrade and Automated Refactoring of any PHP code",
"support": {
"issues": "https://github.com/rectorphp/rector/issues",
"source": "https://github.com/rectorphp/rector/tree/0.12.23"
},
"funding": [
{
"url": "https://github.com/tomasvotruba",
"type": "github"
}
],
"time": "2022-05-01T15:50:16+00:00"
},
{
"name": "sanmai/later",
"version": "0.1.2",

24
rector.php Normal file
View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__FILE__,
__DIR__ . '/src',
__DIR__ . '/tests',
]);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);
$rectorConfig->parallel();
$rectorConfig->skip([
AddLiteralSeparatorToNumberRector::class,
]);
};

View File

@ -82,18 +82,14 @@ final class Container
public function __construct(Settings $settings)
{
$this->factories = [
TreeMapper::class => function (): TreeMapper {
return new TreeMapperContainer(
$this->get(TypeParser::class),
new RootNodeBuilder($this->get(NodeBuilder::class))
);
},
TreeMapper::class => fn () => new TreeMapperContainer(
$this->get(TypeParser::class),
new RootNodeBuilder($this->get(NodeBuilder::class))
),
ShellVisitor::class => function (): ShellVisitor {
return new AttributeShellVisitor();
},
ShellVisitor::class => fn () => new AttributeShellVisitor(),
NodeBuilder::class => function () use ($settings): NodeBuilder {
NodeBuilder::class => function () use ($settings) {
$listNodeBuilder = new ListNodeBuilder();
$arrayNodeBuilder = new ArrayNodeBuilder();
@ -140,7 +136,7 @@ final class Container
return new ErrorCatcherNodeBuilder($builder);
},
ObjectBuilderFactory::class => function () use ($settings): ObjectBuilderFactory {
ObjectBuilderFactory::class => function () use ($settings) {
$constructors = new FunctionsContainer(
$this->get(FunctionDefinitionRepository::class),
$settings->customConstructors
@ -166,7 +162,7 @@ final class Container
ObjectBuilderFilterer::class => fn () => new ObjectBuilderFilterer(),
ClassDefinitionRepository::class => function () use ($settings): ClassDefinitionRepository {
ClassDefinitionRepository::class => function () use ($settings) {
$repository = new ReflectionClassDefinitionRepository(
$this->get(TypeParserFactory::class),
$this->get(AttributesRepository::class),
@ -179,7 +175,7 @@ final class Container
return new CacheClassDefinitionRepository($repository, $cache);
},
FunctionDefinitionRepository::class => function () use ($settings): FunctionDefinitionRepository {
FunctionDefinitionRepository::class => function () use ($settings) {
$repository = new ReflectionFunctionDefinitionRepository(
$this->get(TypeParserFactory::class),
$this->get(AttributesRepository::class),
@ -192,7 +188,7 @@ final class Container
return new CacheFunctionDefinitionRepository($repository, $cache);
},
AttributesRepository::class => function () use ($settings): AttributesRepository {
AttributesRepository::class => function () use ($settings) {
if (! $settings->enableLegacyDoctrineAnnotations) {
return new NativeAttributesRepository();
}
@ -207,22 +203,18 @@ final class Container
return new DoctrineAnnotationsRepository(); // @codeCoverageIgnoreEnd
},
TypeParserFactory::class => function (): TypeParserFactory {
return new LexingTypeParserFactory(
$this->get(TemplateParser::class)
);
},
TypeParserFactory::class => fn () => new LexingTypeParserFactory(
$this->get(TemplateParser::class)
),
TypeParser::class => function (): TypeParser {
TypeParser::class => function () {
$factory = $this->get(TypeParserFactory::class);
$parser = $factory->get(new HandleClassGenericSpecification());
return new CachedParser($parser);
},
TemplateParser::class => function (): TemplateParser {
return new BasicTemplateParser();
},
TemplateParser::class => fn () => new BasicTemplateParser(),
];
}

View File

@ -36,6 +36,7 @@ final class JsonSource implements IteratorAggregate
}
// @codeCoverageIgnoreEnd
/** @noRector \Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector */
$source = json_decode($jsonSource, true);
if ($source === null) {

View File

@ -149,9 +149,7 @@ final class InterfaceInferringMappingTest extends IntegrationTest
{
try {
$this->mapperBuilder
->infer(SomeInterface::class, function (string $type, int $key): string {
return SomeClassThatInheritsInterfaceA::class;
})
->infer(SomeInterface::class, fn (string $type, int $key): string => SomeClassThatInheritsInterfaceA::class)
->mapper()
->map(SomeInterface::class, 42);
} catch (MappingError $exception) {
@ -166,9 +164,7 @@ final class InterfaceInferringMappingTest extends IntegrationTest
{
try {
$this->mapperBuilder
->infer(SomeInterface::class, function (int $key): string {
return SomeClassThatInheritsInterfaceA::class;
})
->infer(SomeInterface::class, fn (int $key): string => SomeClassThatInheritsInterfaceA::class)
->mapper()
->map(SomeInterface::class, 'foo');
} catch (MappingError $exception) {

View File

@ -29,9 +29,7 @@ final class ReflectionFunctionDefinitionRepositoryTest extends TestCase
/**
* @param string $parameterWithDocBlockType
*/
$callback = function (string $foo, $parameterWithDocBlockType): string {
return $foo . $parameterWithDocBlockType;
};
$callback = fn (string $foo, $parameterWithDocBlockType): string => $foo . $parameterWithDocBlockType;
$function = $this->repository->for($callback);
$parameters = $function->parameters();

View File

@ -96,7 +96,7 @@ final class ReflectionTest extends TestCase
public function test_nullable_scalar_type_is_handled(): void
{
$object = new class () {
public ?string $someProperty;
public ?string $someProperty = null;
};
/** @var ReflectionType $type */