Skip to content

Commit f8b0ac3

Browse files
TomasVotrubakaizen-ci
andauthored
update to new phpstan rules, add static fixes (#18)
* update to new phpstan rules, add static fixes * [ci-review] Rector Rectify Co-authored-by: kaizen-ci <info@kaizen-ci.org>
1 parent 70ef6eb commit f8b0ac3

12 files changed

Lines changed: 83 additions & 70 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"phpstan/phpstan-nette": "^0.12.16",
5757
"phpunit/phpunit": "^9.5",
5858
"rector/rector-generator": "^0.1.7",
59-
"rector/rector-phpstan-rules": "^0.1",
59+
"rector/rector-phpstan-rules": "^0.2.3",
6060
"symplify/coding-standard": "^9.3.5",
6161
"symplify/easy-ci": "^9.3.5",
6262
"symplify/easy-coding-standard": "^9.3.5",

config/services.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
use Rector\Core\Console\ConsoleApplication;
3232
use Rector\Core\PhpParser\Parser\NikicPhpParserFactory;
3333
use Rector\Core\PhpParser\Parser\PhpParserLexerFactory;
34-
use Rector\FileFormatter\Contract\EditorConfig\EditorConfigParserInterface;
35-
use Rector\FileFormatter\EditorConfig\EditorConfigIdiosyncraticParser;
3634
use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory;
3735
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator;
3836
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
@@ -155,6 +153,4 @@
155153
$services->set(Formatter::class);
156154

157155
$services->set(EditorConfig::class);
158-
159-
$services->alias(EditorConfigParserInterface::class, EditorConfigIdiosyncraticParser::class);
160156
};

packages-tests/FileFormatter/EditorConfig/EditorConfigIdiosyncraticParser/.editorconfig renamed to packages-tests/FileFormatter/EditorConfig/EditorConfigParser/.editorconfig

File renamed without changes.

packages-tests/FileFormatter/EditorConfig/EditorConfigIdiosyncraticParser/EditorConfigIdiosyncraticParserTest.php renamed to packages-tests/FileFormatter/EditorConfig/EditorConfigParser/EditorConfigParserTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
<?php
22

3-
namespace Rector\Tests\FileFormatter\EditorConfig\EditorConfigIdiosyncraticParser;
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\FileFormatter\EditorConfig\EditorConfigParser;
46

57
use Rector\Core\ValueObject\Application\File;
6-
use Rector\FileFormatter\Contract\EditorConfig\EditorConfigParserInterface;
8+
use Rector\FileFormatter\EditorConfig\EditorConfigParser;
79
use Rector\FileFormatter\ValueObject\Indent;
810
use Rector\FileFormatter\ValueObjectFactory\EditorConfigConfigurationBuilder;
911
use Rector\Testing\PHPUnit\AbstractTestCase;
1012
use Symplify\SmartFileSystem\SmartFileInfo;
1113

12-
final class EditorConfigIdiosyncraticParserTest extends AbstractTestCase
14+
final class EditorConfigParserTest extends AbstractTestCase
1315
{
1416
/**
15-
* @var EditorConfigParserInterface
17+
* @var EditorConfigParser
1618
*/
1719
private $editorConfigParser;
1820

1921
protected function setUp(): void
2022
{
2123
$this->boot();
22-
$this->editorConfigParser = $this->getService(EditorConfigParserInterface::class);
24+
$this->editorConfigParser = $this->getService(EditorConfigParser::class);
2325
}
2426

2527
public function testComposerJsonFile(): void

packages-tests/FileFormatter/EditorConfig/EditorConfigIdiosyncraticParser/Fixture/composer.json renamed to packages-tests/FileFormatter/EditorConfig/EditorConfigParser/Fixture/composer.json

File renamed without changes.

packages/FileFormatter/Contract/EditorConfig/EditorConfigParserInterface.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/FileFormatter/EditorConfig/EditorConfigIdiosyncraticParser.php renamed to packages/FileFormatter/EditorConfig/EditorConfigParser.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use Idiosyncratic\EditorConfig\EditorConfig;
88
use Rector\Core\ValueObject\Application\File;
9-
use Rector\FileFormatter\Contract\EditorConfig\EditorConfigParserInterface;
109
use Rector\FileFormatter\ValueObject\EditorConfigConfiguration;
10+
use Rector\FileFormatter\ValueObject\EditorConfigOption;
1111
use Rector\FileFormatter\ValueObjectFactory\EditorConfigConfigurationBuilder;
1212

1313
/**
14-
* @see \Rector\Tests\FileFormatter\EditorConfig\EditorConfigIdiosyncraticParser\EditorConfigIdiosyncraticParserTest
14+
* @see \Rector\Tests\FileFormatter\EditorConfig\EditorConfigParser\EditorConfigParserTest
1515
*/
16-
final class EditorConfigIdiosyncraticParser implements EditorConfigParserInterface
16+
final class EditorConfigParser
1717
{
1818
public function __construct(
1919
private EditorConfig $editorConfig
@@ -27,32 +27,34 @@ public function extractConfigurationForFile(
2727
$smartFileInfo = $file->getSmartFileInfo();
2828
$configuration = $this->editorConfig->getConfigForPath($smartFileInfo->getRealPath());
2929

30-
if (array_key_exists(self::INDENT_STYLE, $configuration)) {
31-
$indentStyle = (string) $configuration[self::INDENT_STYLE]->getValue();
30+
if (array_key_exists(EditorConfigOption::INDENT_STYLE, $configuration)) {
31+
$indentStyle = (string) $configuration[EditorConfigOption::INDENT_STYLE]->getValue();
3232

3333
$editorConfigConfigurationBuilder->withIndentStyle($indentStyle);
3434
}
3535

36-
if (array_key_exists(self::INDENT_SIZE, $configuration)) {
37-
$indentSize = (int) $configuration[self::INDENT_SIZE]->getValue();
36+
if (array_key_exists(EditorConfigOption::INDENT_SIZE, $configuration)) {
37+
$indentSize = (int) $configuration[EditorConfigOption::INDENT_SIZE]->getValue();
3838

3939
$editorConfigConfigurationBuilder->withIndentSize($indentSize);
4040
}
4141

42-
if (array_key_exists(self::END_OF_LINE, $configuration)) {
43-
$endOfLine = (string) $configuration[self::END_OF_LINE]->getValue();
42+
if (array_key_exists(EditorConfigOption::END_OF_LINE, $configuration)) {
43+
$endOfLine = (string) $configuration[EditorConfigOption::END_OF_LINE]->getValue();
4444

4545
$editorConfigConfigurationBuilder->withEndOfLineFromEditorConfig($endOfLine);
4646
}
4747

48-
if (array_key_exists(self::INSERT_FINAL_NEWLINE, $configuration)) {
49-
$insertFinalNewline = (bool) $configuration[self::INSERT_FINAL_NEWLINE]->getValue();
48+
if (array_key_exists(EditorConfigOption::INSERT_FINAL_NEWLINE, $configuration)) {
49+
$insertFinalNewline = (bool) $configuration[EditorConfigOption::INSERT_FINAL_NEWLINE]->getValue();
5050

5151
$editorConfigConfigurationBuilder->withInsertFinalNewline($insertFinalNewline);
5252
}
5353

54-
if (array_key_exists(self::TAB_WIDTH, $configuration)) {
55-
$editorConfigConfigurationBuilder->withIndentSize($configuration[self::TAB_WIDTH]->getValue());
54+
if (array_key_exists(EditorConfigOption::TAB_WIDTH, $configuration)) {
55+
$editorConfigConfigurationBuilder->withIndentSize(
56+
$configuration[EditorConfigOption::TAB_WIDTH]->getValue()
57+
);
5658
}
5759

5860
return $editorConfigConfigurationBuilder->build();

packages/FileFormatter/FileFormatter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use Rector\Core\Configuration\Option;
88
use Rector\Core\ValueObject\Application\File;
9-
use Rector\FileFormatter\Contract\EditorConfig\EditorConfigParserInterface;
109
use Rector\FileFormatter\Contract\Formatter\FileFormatterInterface;
10+
use Rector\FileFormatter\EditorConfig\EditorConfigParser;
1111
use Rector\FileFormatter\Exception\InvalidNewLineStringException;
1212
use Rector\FileFormatter\Exception\ParseIndentException;
1313
use Rector\FileFormatter\ValueObject\EditorConfigConfiguration;
@@ -22,7 +22,7 @@ final class FileFormatter
2222
* @param FileFormatterInterface[] $fileFormatters
2323
*/
2424
public function __construct(
25-
private EditorConfigParserInterface $editorConfigParser,
25+
private EditorConfigParser $editorConfigParser,
2626
private ParameterProvider $parameterProvider,
2727
private array $fileFormatters = []
2828
) {
@@ -62,13 +62,13 @@ private function sniffOriginalFileContent(
6262
try {
6363
$indent = Indent::fromContent($file->getOriginalFileContent());
6464
$editorConfigConfigurationBuilder->withIndent($indent);
65-
} catch (ParseIndentException $parseIndentException) {
65+
} catch (ParseIndentException) {
6666
}
6767

6868
try {
6969
$newLine = NewLine::fromContent($file->getOriginalFileContent());
7070
$editorConfigConfigurationBuilder->withNewLine($newLine);
71-
} catch (InvalidNewLineStringException $invalidNewLineStringException) {
71+
} catch (InvalidNewLineStringException) {
7272
}
7373
}
7474

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\FileFormatter\ValueObject;
6+
7+
final class EditorConfigOption
8+
{
9+
/**
10+
* @var string
11+
*/
12+
public const INDENT_STYLE = 'indent_style';
13+
14+
/**
15+
* @var string
16+
*/
17+
public const INDENT_SIZE = 'indent_size';
18+
19+
/**
20+
* @var string
21+
*/
22+
public const END_OF_LINE = 'end_of_line';
23+
24+
/**
25+
* @var string
26+
*/
27+
public const INSERT_FINAL_NEWLINE = 'insert_final_newline';
28+
29+
/**
30+
* @var string
31+
*/
32+
public const TAB_WIDTH = 'tab_width';
33+
}

phpstan.neon

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ includes:
33
- vendor/symplify/phpstan-rules/config/code-complexity-rules.neon
44
- vendor/symplify/phpstan-rules/config/doctrine-rules.neon
55
- vendor/symplify/phpstan-rules/config/forbidden-static-rules.neon
6-
- vendor/symplify/phpstan-rules/config/generic-rules.neon
76
- vendor/symplify/phpstan-rules/config/naming-rules.neon
87
- vendor/symplify/phpstan-rules/config/regex-rules.neon
98
- vendor/symplify/phpstan-rules/config/services-rules.neon
@@ -17,7 +16,6 @@ parameters:
1716
level: max
1817

1918
paths:
20-
- ecs.php
2119
- rector.php
2220
- bin
2321
- src
@@ -505,3 +503,11 @@ parameters:
505503
-
506504
message: '#Do not call parent method if parent method is empty#'
507505
path: packages/BetterPhpDocParser/PhpDoc/DoctrineAnnotationTagValueNode.php
506+
507+
# upgrade to PHP 7.4 wip
508+
- '#This property type might be inlined to PHP\. Do you have confidence it is correct\? Put it here#'
509+
510+
# special case - cleanup in the future
511+
-
512+
message: '#File processor must require Rector rules in constructor via TypeRectorInterface\[\] \$typeRectors array autowire#'
513+
path: src/Application/FileProcessor/PhpFileProcessor.php

0 commit comments

Comments
 (0)