Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 09a3ae4

Browse files
authored
Update fixers (#25)
* fix: Disable method_separation fixer feat: upgraded kubawerlos/php-cs-fixer-custom-fixers version feat: added new fixers DataProviderNameFixer, NoUselessSprintfFixer, PhpUnitNoUselessReturnFixer, SingleLineThrowFixer, NoDuplicatedImportsFixer, DataProviderReturnTypeFixer, CommentSurroundedBySpacesFixer * feat: updated phpstan rules * feat: added testing-helper to use assertArraySubset * feat: upgraded php version * style: cs fixes
1 parent 74812f9 commit 09a3ae4

File tree

6 files changed

+73
-32
lines changed

6 files changed

+73
-32
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ composer.lock
66
.php_cs.cache
77
.DS_Store
88
Thumbs.db
9+
10+
/.phpunit.result.cache

.travis.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- php: 7.4snapshot
2727

2828
include:
29-
- stage: Test
30-
php: 7.1
31-
env: REMOVE_XDEBUG=true
3229
- stage: Test
3330
php: 7.2
3431
env: REMOVE_XDEBUG=true
@@ -42,18 +39,19 @@ jobs:
4239
php: nightly
4340
# env: REMOVE_XDEBUG=true
4441

45-
- stage: Coding standard
42+
- stage: Static Analysis
4643
if: type != cron
4744
php: 7.3
48-
env: REMOVE_XDEBUG=true
45+
env: REMOVE_XDEBUG=false
4946
script:
50-
- ./vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
47+
- ./vendor/bin/phpstan analyse -c phpstan.neon src
48+
5149
- stage: Coding standard
5250
if: type != cron
5351
php: 7.3
54-
env: REMOVE_XDEBUG=false
52+
env: REMOVE_XDEBUG=true
5553
script:
56-
- ./vendor/bin/phpstan analyse -c phpstan.neon -l 7 src
54+
- ./vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
5755

5856
- stage: Coverage
5957
if: type != cron

composer.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@
2020
}
2121
],
2222
"require": {
23-
"php": "^7.1",
23+
"php": "^7.2",
2424
"friendsofphp/php-cs-fixer": "~2.15.1",
25-
"kubawerlos/php-cs-fixer-custom-fixers": "^1.13.0",
25+
"kubawerlos/php-cs-fixer-custom-fixers": "^1.15.1",
2626
"pedrotroller/php-cs-custom-fixer": "^2.18.1"
2727
},
2828
"require-dev": {
29-
"phpstan/phpstan": "^0.11.12",
29+
"narrowspark/testing-helper": "^8.0.1",
30+
"phpstan/phpstan": "^0.11.16",
3031
"phpstan/phpstan-deprecation-rules": "^0.11.2",
3132
"phpstan/phpstan-phpunit": "^0.11.2",
3233
"phpstan/phpstan-strict-rules": "^0.11.1",
33-
"phpunit/phpunit": "^7.5.13"
34+
"phpunit/phpunit": "^8.4.1",
35+
"thecodingmachine/phpstan-strict-rules": "^0.11.2"
3436
},
3537
"config": {
3638
"sort-packages": true
@@ -50,7 +52,7 @@
5052
"scripts": {
5153
"coverage": "phpunit --coverage-html=\"build/logs\"",
5254
"cs": "php-cs-fixer fix -vvv",
53-
"phpstan": "phpstan analyse -c phpstan.neon -l 7 src --memory-limit=-1",
55+
"phpstan": "phpstan analyse -c phpstan.neon src --memory-limit=-1",
5456
"test": "phpunit"
5557
},
5658
"support": {

phpstan.neon

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
includes:
2-
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
3-
- vendor/phpstan/phpstan-phpunit/extension.neon
4-
- vendor/phpstan/phpstan-phpunit/rules.neon
5-
- vendor/phpstan/phpstan-strict-rules/rules.neon
2+
- %rootDir%/../phpstan-deprecation-rules/rules.neon
3+
- %rootDir%/../phpstan-phpunit/extension.neon
4+
- %rootDir%/../phpstan-phpunit/rules.neon
5+
- %rootDir%/../phpstan-strict-rules/rules.neon
6+
- %rootDir%/../../thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
7+
- %rootDir%/../phpstan/conf/bleedingEdge.neon
68

79
parameters:
10+
level: max
11+
inferPrivatePropertyTypeFromConstructor: true
12+
813
autoload_directories:
914
- %currentWorkingDirectory%/src
1015

11-
ignoreErrors:
16+
ignoreErrors:

src/Config.php

+26-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
namespace Narrowspark\CS\Config;
66

77
use PhpCsFixer\Config as CsConfig;
8+
use PhpCsFixerCustomFixers\Fixer\CommentSurroundedBySpacesFixer;
9+
use PhpCsFixerCustomFixers\Fixer\DataProviderNameFixer;
10+
use PhpCsFixerCustomFixers\Fixer\DataProviderReturnTypeFixer;
811
use PhpCsFixerCustomFixers\Fixer\InternalClassCasingFixer;
912
use PhpCsFixerCustomFixers\Fixer\MultilineCommentOpeningClosingAloneFixer;
1013
use PhpCsFixerCustomFixers\Fixer\NoCommentedOutCodeFixer;
1114
use PhpCsFixerCustomFixers\Fixer\NoDoctrineMigrationsGeneratedCommentFixer;
15+
use PhpCsFixerCustomFixers\Fixer\NoDuplicatedImportsFixer;
1216
use PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer;
1317
use PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer;
1418
use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer;
@@ -17,6 +21,7 @@
1721
use PhpCsFixerCustomFixers\Fixer\NoUnneededConcatenationFixer;
1822
use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer;
1923
use PhpCsFixerCustomFixers\Fixer\NoUselessDoctrineRepositoryCommentFixer;
24+
use PhpCsFixerCustomFixers\Fixer\NoUselessSprintfFixer;
2025
use PhpCsFixerCustomFixers\Fixer\NullableParamStyleFixer;
2126
use PhpCsFixerCustomFixers\Fixer\OperatorLinebreakFixer;
2227
use PhpCsFixerCustomFixers\Fixer\PhpdocNoIncorrectVarAnnotationFixer;
@@ -25,6 +30,8 @@
2530
use PhpCsFixerCustomFixers\Fixer\PhpdocParamTypeFixer;
2631
use PhpCsFixerCustomFixers\Fixer\PhpdocSelfAccessorFixer;
2732
use PhpCsFixerCustomFixers\Fixer\PhpdocSingleLineVarFixer;
33+
use PhpCsFixerCustomFixers\Fixer\PhpUnitNoUselessReturnFixer;
34+
use PhpCsFixerCustomFixers\Fixer\SingleLineThrowFixer;
2835
use PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer;
2936
use PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer;
3037

@@ -67,7 +74,7 @@ public function __construct(string $header = null, array $overwriteConfig = [])
6774
}
6875

6976
/**
70-
* @return array
77+
* @return array<int|string, mixed>
7178
*/
7279
public function getRules(): array
7380
{
@@ -86,7 +93,7 @@ public function getRules(): array
8693
}
8794

8895
/**
89-
* @return array
96+
* @return array<string, array<string, int|true>|bool>
9097
*/
9198
protected function getPedroTrollerRules(): array
9299
{
@@ -107,7 +114,7 @@ protected function getPedroTrollerRules(): array
107114
}
108115

109116
/**
110-
* @return array
117+
* @return array<string, bool>
111118
*/
112119
protected function getKubawerlosRules(): array
113120
{
@@ -134,11 +141,18 @@ protected function getKubawerlosRules(): array
134141
PhpdocSingleLineVarFixer::name() => true,
135142
SingleSpaceAfterStatementFixer::name() => true,
136143
SingleSpaceBeforeStatementFixer::name() => true,
144+
DataProviderNameFixer::name() => true,
145+
NoUselessSprintfFixer::name() => true,
146+
PhpUnitNoUselessReturnFixer::name() => true,
147+
SingleLineThrowFixer::name() => true,
148+
NoDuplicatedImportsFixer::name() => true,
149+
DataProviderReturnTypeFixer::name() => true,
150+
CommentSurroundedBySpacesFixer::name() => true,
137151
];
138152
}
139153

140154
/**
141-
* @return array
155+
* @return array<string, array<string, array<int, string>|bool|string>|bool>
142156
*/
143157
protected function getPhp71Rules(): array
144158
{
@@ -161,6 +175,9 @@ protected function getPhp71Rules(): array
161175
];
162176
}
163177

178+
/**
179+
* @return array<string, bool>
180+
*/
164181
protected function getPhp73Rules(): array
165182
{
166183
return [
@@ -169,7 +186,7 @@ protected function getPhp73Rules(): array
169186
}
170187

171188
/**
172-
* @return array
189+
* @return array<string, array<string, array<int, string>|bool|string>|bool>
173190
*/
174191
protected function getContribRules(): array
175192
{
@@ -259,7 +276,7 @@ protected function getContribRules(): array
259276
}
260277

261278
/**
262-
* @return array
279+
* @return array<string, array<string, array<int, string>|bool|string>|bool>
263280
*/
264281
protected function getPsr12Rules(): array
265282
{
@@ -311,7 +328,7 @@ protected function getPsr12Rules(): array
311328
}
312329

313330
/**
314-
* @return array
331+
* @return array<string, array<string, array<int, string>|bool|string>|bool>
315332
*/
316333
protected function getPHPUnitRules(): array
317334
{
@@ -349,7 +366,7 @@ protected function getPHPUnitRules(): array
349366
}
350367

351368
/**
352-
* @return array
369+
* @return array<string, array<string, array<int, string>|bool|string>|bool>
353370
*/
354371
protected function getSymfonyRules(): array
355372
{
@@ -430,7 +447,7 @@ protected function getSymfonyRules(): array
430447
'non_printable_character' => true,
431448
'lowercase_cast' => true,
432449
'magic_method_casing' => true,
433-
'method_separation' => true,
450+
'method_separation' => false,
434451
'native_function_casing' => true,
435452
'native_function_invocation' => true,
436453
'new_with_braces' => true,

tests/ConfigTest.php

+22-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
namespace Narrowspark\CS\Config\Tests;
66

77
use Narrowspark\CS\Config\Config;
8+
use Narrowspark\TestingHelper\Traits\AssertArrayTrait;
89
use PhpCsFixer\ConfigInterface;
910
use PhpCsFixer\Fixer\FixerInterface;
1011
use PhpCsFixer\FixerFactory;
1112
use PhpCsFixer\RuleSet;
13+
use PhpCsFixerCustomFixers\Fixer\CommentSurroundedBySpacesFixer;
14+
use PhpCsFixerCustomFixers\Fixer\DataProviderNameFixer;
15+
use PhpCsFixerCustomFixers\Fixer\DataProviderReturnTypeFixer;
1216
use PhpCsFixerCustomFixers\Fixer\InternalClassCasingFixer;
1317
use PhpCsFixerCustomFixers\Fixer\MultilineCommentOpeningClosingAloneFixer;
1418
use PhpCsFixerCustomFixers\Fixer\NoCommentedOutCodeFixer;
1519
use PhpCsFixerCustomFixers\Fixer\NoDoctrineMigrationsGeneratedCommentFixer;
20+
use PhpCsFixerCustomFixers\Fixer\NoDuplicatedImportsFixer;
1621
use PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer;
1722
use PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer;
1823
use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer;
@@ -21,6 +26,7 @@
2126
use PhpCsFixerCustomFixers\Fixer\NoUnneededConcatenationFixer;
2227
use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer;
2328
use PhpCsFixerCustomFixers\Fixer\NoUselessDoctrineRepositoryCommentFixer;
29+
use PhpCsFixerCustomFixers\Fixer\NoUselessSprintfFixer;
2430
use PhpCsFixerCustomFixers\Fixer\NullableParamStyleFixer;
2531
use PhpCsFixerCustomFixers\Fixer\OperatorLinebreakFixer;
2632
use PhpCsFixerCustomFixers\Fixer\PhpdocNoIncorrectVarAnnotationFixer;
@@ -29,6 +35,8 @@
2935
use PhpCsFixerCustomFixers\Fixer\PhpdocParamTypeFixer;
3036
use PhpCsFixerCustomFixers\Fixer\PhpdocSelfAccessorFixer;
3137
use PhpCsFixerCustomFixers\Fixer\PhpdocSingleLineVarFixer;
38+
use PhpCsFixerCustomFixers\Fixer\PhpUnitNoUselessReturnFixer;
39+
use PhpCsFixerCustomFixers\Fixer\SingleLineThrowFixer;
3240
use PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer;
3341
use PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer;
3442
use PHPUnit\Framework\TestCase;
@@ -40,6 +48,8 @@
4048
*/
4149
final class ConfigTest extends TestCase
4250
{
51+
use AssertArrayTrait;
52+
4353
public function testImplementsInterface(): void
4454
{
4555
self::assertInstanceOf(ConfigInterface::class, new Config());
@@ -169,7 +179,7 @@ public function testAllConfiguredRulesAreBuiltIn(): void
169179
}
170180

171181
/**
172-
* @dataProvider providerDoesNotHaveFixerEnabled
182+
* @dataProvider provideDoesNotHaveRulesEnabledCases
173183
*
174184
* @param string $fixer
175185
* @param array|string $reason
@@ -199,7 +209,7 @@ public function testDoesNotHaveRulesEnabled(string $fixer, $reason): void
199209
/**
200210
* @return array
201211
*/
202-
public function providerDoesNotHaveFixerEnabled(): array
212+
public function provideDoesNotHaveRulesEnabledCases(): iterable
203213
{
204214
$symfonyFixers = [
205215
'self_accessor' => 'it causes an edge case error',
@@ -244,7 +254,7 @@ public function testHeaderCommentFixerIsDisabledByDefault(): void
244254
}
245255

246256
/**
247-
* @dataProvider providerValidHeader
257+
* @dataProvider provideHeaderCommentFixerIsEnabledIfHeaderIsProvidedCases
248258
*
249259
* @param string $header
250260
*/
@@ -265,7 +275,7 @@ public function testHeaderCommentFixerIsEnabledIfHeaderIsProvided($header): void
265275
/**
266276
* @return \Generator
267277
*/
268-
public function providerValidHeader(): \Generator
278+
public function provideHeaderCommentFixerIsEnabledIfHeaderIsProvidedCases(): iterable
269279
{
270280
$values = [
271281
'string-empty' => '',
@@ -362,6 +372,13 @@ protected function getKubawerlosRules(): array
362372
PhpdocSingleLineVarFixer::name() => true,
363373
SingleSpaceAfterStatementFixer::name() => true,
364374
SingleSpaceBeforeStatementFixer::name() => true,
375+
DataProviderNameFixer::name() => true,
376+
NoUselessSprintfFixer::name() => true,
377+
PhpUnitNoUselessReturnFixer::name() => true,
378+
SingleLineThrowFixer::name() => true,
379+
NoDuplicatedImportsFixer::name() => true,
380+
DataProviderReturnTypeFixer::name() => true,
381+
CommentSurroundedBySpacesFixer::name() => true,
365382
];
366383
}
367384

@@ -637,7 +654,7 @@ protected function getSymfonyRules(): array
637654
'non_printable_character' => true,
638655
'lowercase_cast' => true,
639656
'magic_method_casing' => true,
640-
'method_separation' => true,
657+
'method_separation' => false,
641658
'native_function_casing' => true,
642659
'native_function_invocation' => true,
643660
'new_with_braces' => true,

0 commit comments

Comments
 (0)