Skip to content

Commit

Permalink
#91 - ordering and grouping imports (#92)
Browse files Browse the repository at this point in the history
* #91 - ordering and grouping imports

* #91 - dependencies update

* #91 - reordering
  • Loading branch information
krzysztofrewak authored May 19, 2023
1 parent cc9ca1a commit e7d822f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "library",
"require": {
"php": "^8.1",
"friendsofphp/php-cs-fixer": "^3.15",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.13"
"friendsofphp/php-cs-fixer": "^3.16",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.14"
},
"require-dev": {
"jetbrains/phpstorm-attributes": "^1.0",
Expand Down
9 changes: 6 additions & 3 deletions src/Configuration/Defaults/CommonRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer;
use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer;
use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer;
use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer;
use PhpCsFixer\Fixer\Casing\LowercaseStaticReferenceFixer;
use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer;
Expand Down Expand Up @@ -93,6 +92,7 @@
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\SimpleToComplexStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBetweenImportGroupsFixer;
use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer;
use PhpCsFixer\Fixer\Whitespace\LineEndingFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
Expand Down Expand Up @@ -198,7 +198,10 @@ class CommonRules extends Rules
VoidReturnFixer::class => true,
UseArrowFunctionsFixer::class => true,
FullyQualifiedStrictTypesFixer::class => true,
OrderedImportsFixer::class => true,
OrderedImportsFixer::class => [
"sort_algorithm" => "alpha",
"imports_order" => ["class", "function", "const"],
],
PhpdocLineSpanFixer::class => [
"const" => "single",
"property" => "single",
Expand Down Expand Up @@ -272,7 +275,6 @@ class CommonRules extends Rules
PhpdocNoIncorrectVarAnnotationFixer::class => true,
PhpdocNoSuperfluousParamFixer::class => true,
PhpdocParamOrderFixer::class => true,
BracesFixer::class => true,
NoSpacesInsideParenthesisFixer::class => true,
YodaStyleFixer::class => [
"equal" => false,
Expand Down Expand Up @@ -301,5 +303,6 @@ class CommonRules extends Rules
MultilineWhitespaceBeforeSemicolonsFixer::class => true,
LineEndingFixer::class => true,
StatementIndentationFixer::class => true,
BlankLineBetweenImportGroupsFixer::class => true,
];
}
1 change: 1 addition & 0 deletions tests/codestyle/CodestyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static function providePhp80Fixtures(): array
["anonymousFunctions"],
["namespaces"],
["emptyLines"],
["importsOrder"],
];
}

Expand Down
26 changes: 26 additions & 0 deletions tests/codestyle/fixtures/importsOrder/actual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use function array_merge;
use function assert;
use Something\Api;
use Something\Paths;
use const Something\CONSTANT;
use Whatever\File;

use Whatever\SpecificationFile;
use Whatever\Reader;

class Merge
{
public function do(array $a, array $b): void
{
$merge = array_merge($a, $b);

$reader = new Reader(new SpecificationFile(new File()), new Paths());
$result = $reader->merge($merge, new Api(), flag: CONSTANT);

assert($result);
}
}
27 changes: 27 additions & 0 deletions tests/codestyle/fixtures/importsOrder/expected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Something\Api;
use Something\Paths;
use Whatever\File;
use Whatever\Reader;
use Whatever\SpecificationFile;

use function array_merge;
use function assert;

use const Something\CONSTANT;

class Merge
{
public function do(array $a, array $b): void
{
$merge = array_merge($a, $b);

$reader = new Reader(new SpecificationFile(new File()), new Paths());
$result = $reader->merge($merge, new Api(), flag: CONSTANT);

assert($result);
}
}

0 comments on commit e7d822f

Please sign in to comment.