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

Commit 5645b25

Browse files
authored
feat: updated composer require-dev versions (#21)
feat: updated composer require versions localheinz/php-cs-fixer-config 1.22.* pedrotroller/php-cs-custom-fixer 2.18.1 feat: added kubawerlos/php-cs-fixer-custom-fixers 1.13.0 and added the rules
1 parent 7ee21d7 commit 5645b25

File tree

3 files changed

+148
-27
lines changed

3 files changed

+148
-27
lines changed

composer.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
],
2222
"require": {
2323
"php": "^7.1",
24-
"localheinz/php-cs-fixer-config": "1.19.*",
25-
"pedrotroller/php-cs-custom-fixer": "^2.15.2"
24+
"kubawerlos/php-cs-fixer-custom-fixers": "^1.13.0",
25+
"localheinz/php-cs-fixer-config": "1.22.*",
26+
"pedrotroller/php-cs-custom-fixer": "^2.18.1"
2627
},
2728
"require-dev": {
28-
"phpstan/phpstan": "^0.11.2",
29-
"phpstan/phpstan-deprecation-rules": "^0.11.0",
30-
"phpstan/phpstan-phpunit": "^0.11.0",
31-
"phpstan/phpstan-strict-rules": "^0.11.0",
32-
"phpunit/phpunit": "^7.4.0"
29+
"phpstan/phpstan": "^0.11.12",
30+
"phpstan/phpstan-deprecation-rules": "^0.11.2",
31+
"phpstan/phpstan-phpunit": "^0.11.2",
32+
"phpstan/phpstan-strict-rules": "^0.11.1",
33+
"phpunit/phpunit": "^7.5.13"
3334
},
3435
"config": {
3536
"sort-packages": true

src/Config.php

+65-14
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,37 @@
33
namespace Narrowspark\CS\Config;
44

55
use Localheinz\PhpCsFixer\Config\RuleSet\Php71;
6-
use PedroTroller\CS\Fixer\Fixers;
6+
use Localheinz\PhpCsFixer\Config\RuleSet\Php73;
77
use PhpCsFixer\Config as CsConfig;
8+
use PhpCsFixerCustomFixers\Fixer\InternalClassCasingFixer;
9+
use PhpCsFixerCustomFixers\Fixer\MultilineCommentOpeningClosingAloneFixer;
10+
use PhpCsFixerCustomFixers\Fixer\NoCommentedOutCodeFixer;
11+
use PhpCsFixerCustomFixers\Fixer\NoDoctrineMigrationsGeneratedCommentFixer;
12+
use PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer;
13+
use PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer;
14+
use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer;
15+
use PhpCsFixerCustomFixers\Fixer\NoPhpStormGeneratedCommentFixer;
16+
use PhpCsFixerCustomFixers\Fixer\NoReferenceInFunctionDefinitionFixer;
17+
use PhpCsFixerCustomFixers\Fixer\NoUnneededConcatenationFixer;
18+
use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer;
19+
use PhpCsFixerCustomFixers\Fixer\NoUselessDoctrineRepositoryCommentFixer;
20+
use PhpCsFixerCustomFixers\Fixer\NullableParamStyleFixer;
21+
use PhpCsFixerCustomFixers\Fixer\OperatorLinebreakFixer;
22+
use PhpCsFixerCustomFixers\Fixer\PhpdocNoIncorrectVarAnnotationFixer;
23+
use PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer;
24+
use PhpCsFixerCustomFixers\Fixer\PhpdocParamOrderFixer;
25+
use PhpCsFixerCustomFixers\Fixer\PhpdocParamTypeFixer;
26+
use PhpCsFixerCustomFixers\Fixer\PhpdocSelfAccessorFixer;
27+
use PhpCsFixerCustomFixers\Fixer\PhpdocSingleLineVarFixer;
28+
use PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer;
29+
use PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer;
830

9-
class Config extends CsConfig
31+
final class Config extends CsConfig
1032
{
1133
/**
12-
* A instance of the php 7.1 rule set.
34+
* A instance of the php 7.1 or 7.3 rule set.
1335
*
14-
* @var Php71
36+
* @var \Localheinz\PhpCsFixer\Config\RuleSet\Php71|\Localheinz\PhpCsFixer\Config\RuleSet\Php73
1537
*/
1638
private $ruleSet;
1739

@@ -33,9 +55,10 @@ public function __construct(string $header = null, array $overwriteConfig = [])
3355
parent::__construct('narrowspark');
3456

3557
$this->setRiskyAllowed(true);
36-
$this->registerCustomFixers(new Fixers());
58+
$this->registerCustomFixers(new \PedroTroller\CS\Fixer\Fixers());
59+
$this->registerCustomFixers(new \PhpCsFixerCustomFixers\Fixers());
3760

38-
$this->ruleSet = new Php71($header);
61+
$this->ruleSet = \PHP_VERSION_ID >= 70300 ? new Php73($header) : new Php71($header);
3962
$this->overwriteRules = $overwriteConfig;
4063
}
4164

@@ -48,14 +71,15 @@ public function getRules(): array
4871
'binary_operator_spaces' => [
4972
'default' => 'align',
5073
],
51-
'@DoctrineAnnotation' => true,
52-
'blank_line_after_opening_tag' => false,
53-
'no_blank_lines_before_namespace' => true,
54-
'single_blank_line_before_namespace' => false,
55-
'self_accessor' => false,
56-
'no_homoglyph_names' => false,
57-
'not_operator_with_successor_space' => true,
58-
'increment_style' => [
74+
'@DoctrineAnnotation' => true,
75+
'blank_line_after_opening_tag' => false,
76+
'no_blank_lines_before_namespace' => true,
77+
'single_blank_line_before_namespace' => false,
78+
'self_accessor' => false,
79+
'native_function_type_declaration_casing' => true,
80+
'no_homoglyph_names' => false,
81+
'not_operator_with_successor_space' => true,
82+
'increment_style' => [
5983
'style' => 'post',
6084
],
6185
'mb_str_functions' => false,
@@ -76,6 +100,7 @@ public function getRules(): array
76100
],
77101
'fopen_flags' => false,
78102
'fopen_flag_order' => false,
103+
'php_unit_test_class_requires_covers' => false,
79104
];
80105

81106
$pedroTrollerRules = [
@@ -93,10 +118,36 @@ public function getRules(): array
93118
'PedroTroller/phpspec' => false,
94119
];
95120

121+
$kubawerlosRules = [
122+
InternalClassCasingFixer::name() => true,
123+
MultilineCommentOpeningClosingAloneFixer::name() => false,
124+
NoCommentedOutCodeFixer::name() => true,
125+
NoDoctrineMigrationsGeneratedCommentFixer::name() => true,
126+
NoImportFromGlobalNamespaceFixer::name() => false,
127+
NoLeadingSlashInGlobalNamespaceFixer::name() => true,
128+
NoNullableBooleanTypeFixer::name() => false,
129+
NoPhpStormGeneratedCommentFixer::name() => true,
130+
NoReferenceInFunctionDefinitionFixer::name() => false,
131+
NoUnneededConcatenationFixer::name() => true,
132+
NoUselessCommentFixer::name() => false,
133+
NoUselessDoctrineRepositoryCommentFixer::name() => true,
134+
NullableParamStyleFixer::name() => false,
135+
OperatorLinebreakFixer::name() => true,
136+
PhpdocNoIncorrectVarAnnotationFixer::name() => true,
137+
PhpdocNoSuperfluousParamFixer::name() => true,
138+
PhpdocParamOrderFixer::name() => true,
139+
PhpdocParamTypeFixer::name() => true,
140+
PhpdocSelfAccessorFixer::name() => true,
141+
PhpdocSingleLineVarFixer::name() => true,
142+
SingleSpaceAfterStatementFixer::name() => true,
143+
SingleSpaceBeforeStatementFixer::name() => true,
144+
];
145+
96146
return \array_merge(
97147
$this->ruleSet->rules(),
98148
$overrideRules,
99149
$pedroTrollerRules,
150+
$kubawerlosRules,
100151
$this->overwriteRules
101152
);
102153
}

tests/ConfigTest.php

+75-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
namespace Narrowspark\CS\Config\Tests;
44

55
use Narrowspark\CS\Config\Config;
6-
use PedroTroller\CS\Fixer\Fixers;
76
use PhpCsFixer\ConfigInterface;
87
use PhpCsFixer\FixerFactory;
98
use PhpCsFixer\RuleSet;
9+
use PhpCsFixerCustomFixers\Fixer\InternalClassCasingFixer;
10+
use PhpCsFixerCustomFixers\Fixer\MultilineCommentOpeningClosingAloneFixer;
11+
use PhpCsFixerCustomFixers\Fixer\NoCommentedOutCodeFixer;
12+
use PhpCsFixerCustomFixers\Fixer\NoDoctrineMigrationsGeneratedCommentFixer;
13+
use PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer;
14+
use PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer;
15+
use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer;
16+
use PhpCsFixerCustomFixers\Fixer\NoPhpStormGeneratedCommentFixer;
17+
use PhpCsFixerCustomFixers\Fixer\NoReferenceInFunctionDefinitionFixer;
18+
use PhpCsFixerCustomFixers\Fixer\NoUnneededConcatenationFixer;
19+
use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer;
20+
use PhpCsFixerCustomFixers\Fixer\NoUselessDoctrineRepositoryCommentFixer;
21+
use PhpCsFixerCustomFixers\Fixer\NullableParamStyleFixer;
22+
use PhpCsFixerCustomFixers\Fixer\OperatorLinebreakFixer;
23+
use PhpCsFixerCustomFixers\Fixer\PhpdocNoIncorrectVarAnnotationFixer;
24+
use PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer;
25+
use PhpCsFixerCustomFixers\Fixer\PhpdocParamOrderFixer;
26+
use PhpCsFixerCustomFixers\Fixer\PhpdocParamTypeFixer;
27+
use PhpCsFixerCustomFixers\Fixer\PhpdocSelfAccessorFixer;
28+
use PhpCsFixerCustomFixers\Fixer\PhpdocSingleLineVarFixer;
29+
use PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer;
30+
use PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer;
1031
use PHPUnit\Framework\TestCase;
1132
use ReflectionProperty;
1233

@@ -63,7 +84,8 @@ public function testIfAllRulesAreTested(): void
6384
$this->getPhp71Rules(),
6485
$this->getPhp73Rules(),
6586
$this->getPHPUnitRules(),
66-
$this->getPedroTrollerRules()
87+
$this->getPedroTrollerRules(),
88+
$this->getKubawerlosRules()
6789
);
6890
$rules = (new Config())->getRules();
6991

@@ -107,17 +129,23 @@ public function testAllConfiguredRulesAreBuiltIn(): void
107129
{
108130
$pedroTrollerRules = [];
109131

110-
foreach (new Fixers() as $fixer) {
132+
foreach (new \PedroTroller\CS\Fixer\Fixers() as $fixer) {
111133
if ($fixer->isDeprecated()) {
112134
continue;
113135
}
114136

115137
$pedroTrollerRules[] = $fixer->getName();
116138
}
117139

140+
$kubawerlosRules = [];
141+
142+
foreach (new \PhpCsFixerCustomFixers\Fixers() as $fixer) {
143+
$kubawerlosRules[] = $fixer->getName();
144+
}
145+
118146
$fixersNotBuiltIn = \array_diff(
119147
$this->configuredFixers(),
120-
\array_merge($this->builtInFixers(), $pedroTrollerRules)
148+
\array_merge($this->builtInFixers(), $pedroTrollerRules, $kubawerlosRules)
121149
);
122150

123151
$this->assertEmpty($fixersNotBuiltIn, \sprintf(
@@ -245,6 +273,37 @@ public function getPedroTrollerRules(): array
245273
];
246274
}
247275

276+
/**
277+
* @return array
278+
*/
279+
public function getKubawerlosRules(): array
280+
{
281+
return [
282+
InternalClassCasingFixer::name() => true,
283+
MultilineCommentOpeningClosingAloneFixer::name() => false,
284+
NoCommentedOutCodeFixer::name() => true,
285+
NoDoctrineMigrationsGeneratedCommentFixer::name() => true,
286+
NoImportFromGlobalNamespaceFixer::name() => false,
287+
NoLeadingSlashInGlobalNamespaceFixer::name() => true,
288+
NoNullableBooleanTypeFixer::name() => false,
289+
NoPhpStormGeneratedCommentFixer::name() => true,
290+
NoReferenceInFunctionDefinitionFixer::name() => false,
291+
NoUnneededConcatenationFixer::name() => true,
292+
NoUselessCommentFixer::name() => false,
293+
NoUselessDoctrineRepositoryCommentFixer::name() => true,
294+
NullableParamStyleFixer::name() => false,
295+
OperatorLinebreakFixer::name() => true,
296+
PhpdocNoIncorrectVarAnnotationFixer::name() => true,
297+
PhpdocNoSuperfluousParamFixer::name() => true,
298+
PhpdocParamOrderFixer::name() => true,
299+
PhpdocParamTypeFixer::name() => true,
300+
PhpdocSelfAccessorFixer::name() => true,
301+
PhpdocSingleLineVarFixer::name() => true,
302+
SingleSpaceAfterStatementFixer::name() => true,
303+
SingleSpaceBeforeStatementFixer::name() => true,
304+
];
305+
}
306+
248307
/**
249308
* @return array
250309
*/
@@ -277,6 +336,7 @@ protected function getContribRules(): array
277336
'escape_implicit_backslashes' => true,
278337
'explicit_indirect_variable' => true,
279338
'explicit_string_variable' => true,
339+
'final_class' => true,
280340
'final_internal_class' => true,
281341
'fully_qualified_strict_types' => true,
282342
'general_phpdoc_annotation_remove' => false,
@@ -314,6 +374,7 @@ protected function getContribRules(): array
314374
'no_unset_cast' => true,
315375
'ordered_class_elements' => true,
316376
'ordered_imports' => true,
377+
'ordered_interfaces' => true,
317378
'php_unit_strict' => false,
318379
'php_unit_method_casing' => true,
319380
'php_unit_test_class_requires_covers' => false,
@@ -354,8 +415,10 @@ private function getPHPUnitRules(): array
354415
'php_unit_expectation' => [
355416
'target' => 'newest',
356417
],
357-
'php_unit_mock' => true,
358-
'php_unit_namespaced' => [
418+
'php_unit_dedicate_assert_internal_type' => true,
419+
'php_unit_mock' => true,
420+
'php_unit_mock_short_will_return' => true,
421+
'php_unit_namespaced' => [
359422
'target' => 'newest',
360423
],
361424
'php_unit_no_expectation_annotation' => [
@@ -375,6 +438,7 @@ private function getPHPUnitRules(): array
375438
'php_unit_ordered_covers' => true,
376439
'php_unit_set_up_tear_down_visibility' => true,
377440
'php_unit_strict' => false,
441+
'php_unit_size_class' => true,
378442
'php_unit_test_annotation' => true,
379443
'php_unit_test_class_requires_covers' => false,
380444
];
@@ -471,6 +535,7 @@ private function getSymfonyRules(): array
471535
'native_function_casing' => true,
472536
'native_function_invocation' => true,
473537
'new_with_braces' => true,
538+
'native_function_type_declaration_casing' => true,
474539
'no_alias_functions' => true,
475540
'no_blank_lines_after_class_opening' => true,
476541
'no_blank_lines_after_phpdoc' => true,
@@ -540,8 +605,10 @@ private function getSymfonyRules(): array
540605
'self_accessor' => false,
541606
'short_scalar_cast' => true,
542607
'silenced_deprecation_error' => false,
608+
'simple_to_complex_string_variable' => true,
543609
'single_blank_line_before_namespace' => false,
544610
'single_quote' => true,
611+
'single_trait_insert_per_statement' => true,
545612
'space_after_semicolon' => true,
546613
'single_line_comment_style' => false,
547614
'standardize_not_equals' => true,
@@ -596,6 +663,8 @@ private function configuredFixers(): array
596663
}
597664

598665
/**
666+
* @throws \ReflectionException
667+
*
599668
* @return string[]
600669
*/
601670
private function builtInFixers(): array

0 commit comments

Comments
 (0)