Skip to content

Commit 642f454

Browse files
authored
CS: Add more rector rule sets (#1778)
1 parent efd7611 commit 642f454

43 files changed

Lines changed: 79 additions & 77 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rector.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
<?php
22

3-
use Rector\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector;
43
use Rector\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector;
54
use Rector\CodeQuality\Rector\If_\CombineIfRector;
65
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
76
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
7+
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
8+
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector;
9+
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
810
use Rector\Config\RectorConfig;
911
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
1012
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
11-
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
13+
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
14+
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
1215
use Rector\ValueObject\PhpVersion;
1316

1417
return RectorConfig::configure()
15-
->withRules([
16-
TypedPropertyFromStrictConstructorRector::class
17-
])
1818
->withSkip([
1919
CombineIfRector::class,
2020
ExplicitBoolCompareRector::class,
2121
ForRepeatedCountToOwnVariableRector::class,
2222
RemoveAlwaysTrueIfConditionRector::class => [
2323
__DIR__ . '/src/Processors/ExpandEnums.php',
24-
] ,
24+
],
2525
RemoveDeadInstanceOfRector::class => [
2626
__DIR__ . '/src/Processors/ExpandEnums.php',
2727
],
2828
ShortenElseIfRector::class,
29+
NewlineAfterStatementRector::class,
30+
NullableCompareToNullRector::class,
31+
StringClassNameToClassConstantRector::class => [
32+
__DIR__ . '/src/Analysers/DocBlockParser.php',
33+
],
34+
EncapsedStringsToSprintfRector::class,
35+
ParamTypeByMethodCallTypeRector::class => [
36+
__DIR__ . '/src/Serializer.php',
37+
],
2938
])
30-
->withPreparedSets(true, true)
31-
->withPhpVersion(PhpVersion::PHP_74);
39+
->withPreparedSets(true, true, true, true)
40+
->withPhpVersion(PhpVersion::PHP_74)
41+
->withPhpSets();

src/Analysers/ComposerAutoloaderScanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ComposerAutoloaderScanner
2626
public function scan(array $namespaces): array
2727
{
2828
$units = [];
29-
if ($autoloader = $this->getComposerAutoloader()) {
29+
if ($autoloader = static::getComposerAutoloader()) {
3030
foreach (array_keys($autoloader->getClassMap()) as $unit) {
3131
foreach ($namespaces as $namespace) {
3232
if (0 === strpos($unit, $namespace)) {

src/Analysers/DocBlockAnnotationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function isSupported(): bool
2727
return DocBlockParser::isEnabled();
2828
}
2929

30-
public function setGenerator(Generator $generator)
30+
public function setGenerator(Generator $generator): self
3131
{
3232
$this->generator = $generator;
3333

src/Analysers/DocBlockParser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ public function fromComment(string $comment, Context $context): array
6565
}
6666

6767
return $this->docParser->parse($comment, $context->getDebugLocation());
68-
} catch (\Exception $e) {
69-
if (preg_match('/^(.+) at position ([0-9]+) in ' . preg_quote((string) $context, '/') . '\.$/', $e->getMessage(), $matches)) {
68+
} catch (\Exception $exception) {
69+
if (preg_match('/^(.+) at position ([0-9]+) in ' . preg_quote((string) $context, '/') . '\.$/', $exception->getMessage(), $matches)) {
7070
$errorMessage = $matches[1];
7171
$errorPos = (int) $matches[2];
7272
$atPos = strpos($comment, '@');
7373
$context->line -= substr_count($comment, "\n", $atPos + $errorPos) + 1;
7474
$lines = explode("\n", substr($comment, $atPos, $errorPos));
7575
$context->character = strlen(array_pop($lines)) + 1; // position starts at 0 character starts at 1
76-
$context->logger->error($errorMessage . ' in ' . $context, ['exception' => $e]);
76+
$context->logger->error($errorMessage . ' in ' . $context, ['exception' => $exception]);
7777
} else {
7878
$context->logger->error(
79-
$e->getMessage() . ($context->filename ? ('; file=' . $context->filename) : ''),
80-
['exception' => $e]
79+
$exception->getMessage() . ($context->filename ? ('; file=' . $context->filename) : ''),
80+
['exception' => $exception]
8181
);
8282
}
8383

src/Analysers/TokenScanner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function scanFile(string $filename): array
3131
$parser = (new ParserFactory())->createForNewestSupportedVersion();
3232
try {
3333
$stmts = $parser->parse(file_get_contents($filename));
34-
} catch (Error $e) {
35-
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
34+
} catch (Error $error) {
35+
throw new \RuntimeException($error->getMessage(), $error->getCode(), $error);
3636
}
3737

3838
$result = [];
@@ -59,7 +59,7 @@ protected function collect_stmts(array $stmts, string $namespace): array
5959

6060
return $namespace . '\\' . $name;
6161
};
62-
$details = function () use (&$uses) {
62+
$details = function () use (&$uses): array {
6363
return [
6464
'uses' => $uses,
6565
'interfaces' => [],

src/Analysis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public function unmerged(): Analysis
387387
*
388388
* @return \stdClass {merged: Analysis, unmerged: Analysis}
389389
*/
390-
public function split()
390+
public function split(): \stdClass
391391
{
392392
$result = new \stdClass();
393393
$result->merged = $this->merged();

src/Annotations/AbstractAnnotation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public function jsonSerialize()
434434
* @param string $ref Current ref path?
435435
* @param object $context a free-form context contains
436436
*/
437-
public function validate(array $stack = [], array $skip = [], string $ref = '', $context = null): bool
437+
public function validate(array $stack = [], array $skip = [], string $ref = '', ?object $context = null): bool
438438
{
439439
if (in_array($this, $skip, true)) {
440440
return true;
@@ -792,6 +792,6 @@ protected function combine(...$args): array
792792
}
793793
}
794794

795-
return array_filter($combined, fn ($value) => !Generator::isDefault($value) && $value !== null);
795+
return array_filter($combined, fn ($value): bool => !Generator::isDefault($value) && $value !== null);
796796
}
797797
}

src/Annotations/Components.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Components extends AbstractAnnotation
123123
*/
124124
public static function componentTypes(): array
125125
{
126-
return array_filter(array_keys(self::$_nested), fn ($value) => $value !== Attachable::class);
126+
return array_filter(array_keys(self::$_nested), fn ($value): bool => $value !== Attachable::class);
127127
}
128128

129129
/**

src/Annotations/Items.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Items extends Schema
4141
/**
4242
* @inheritdoc
4343
*/
44-
public function validate(array $stack = [], array $skip = [], string $ref = '', $context = null): bool
44+
public function validate(array $stack = [], array $skip = [], string $ref = '', ?object $context = null): bool
4545
{
4646
if (in_array($this, $skip, true)) {
4747
return true;

src/Annotations/License.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function jsonSerialize()
8686
/**
8787
* @inheritdoc
8888
*/
89-
public function validate(array $stack = [], array $skip = [], string $ref = '', $context = null): bool
89+
public function validate(array $stack = [], array $skip = [], string $ref = '', ?object $context = null): bool
9090
{
9191
$valid = parent::validate($stack, $skip, $ref, $context);
9292

0 commit comments

Comments
 (0)