Skip to content

Commit

Permalink
#132 - ordered class elements (#133)
Browse files Browse the repository at this point in the history
#132 - feat: update fixer configuration, added tests
  • Loading branch information
kamilpiech97 authored Oct 8, 2024
1 parent 8969a80 commit 7aecbaf
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 31 deletions.
26 changes: 25 additions & 1 deletion src/Configuration/Defaults/CommonRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,31 @@ class CommonRules extends Rules
SelfAccessorFixer::class => true,
MagicConstantCasingFixer::class => true,
NoUselessElseFixer::class => true,
OrderedClassElementsFixer::class => true,
OrderedClassElementsFixer::class => [
"order" => [
"use_trait",
"case",
"constant_public",
"constant_protected",
"constant_private",
"property_public",
"property_protected",
"property_private",
"construct",
"destruct",
"magic",
"phpunit",
"property_public_static",
"method_public_static",
"method_public",
"property_protected_static",
"method_protected_static",
"method_protected",
"property_private_static",
"method_private_static",
"method_private",
],
],
NoTrailingWhitespaceInCommentFixer::class => true,
PhpdocTrimConsecutiveBlankLineSeparationFixer::class => true,
PhpdocTrimFixer::class => true,
Expand Down
61 changes: 31 additions & 30 deletions tests/codestyle/CommonRulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,6 @@

class CommonRulesetTest extends CodestyleTestCase
{
/**
* @throws Exception
*/
#[DataProvider("providePhp80Fixtures")]
#[RequiresPhp(">= 8.0")]
public function testPhp80Fixtures(string $name): void
{
$this->testFixture($name);
}

/**
* @throws Exception
*/
#[DataProvider("providePhp81Fixtures")]
#[RequiresPhp(">= 8.1")]
public function testPhp81Fixtures(string $name): void
{
$this->testFixture($name);
}

/**
* @throws Exception
*/
#[DataProvider("providePhp82Fixtures")]
#[RequiresPhp(">= 8.2")]
public function testPhp82Fixtures(string $name): void
{
$this->testFixture($name);
}

public static function providePhp80Fixtures(): array
{
return [
Expand Down Expand Up @@ -69,6 +39,7 @@ public static function providePhp80Fixtures(): array
["compactArray"],
["classesImport"],
["spacesInsideParentheses"],
["orderedClassElements"],
];
}

Expand All @@ -86,4 +57,34 @@ public static function providePhp82Fixtures(): array
["php82"],
];
}

/**
* @throws Exception
*/
#[DataProvider("providePhp80Fixtures")]
#[RequiresPhp(">= 8.0")]
public function testPhp80Fixtures(string $name): void
{
$this->testFixture($name);
}

/**
* @throws Exception
*/
#[DataProvider("providePhp81Fixtures")]
#[RequiresPhp(">= 8.1")]
public function testPhp81Fixtures(string $name): void
{
$this->testFixture($name);
}

/**
* @throws Exception
*/
#[DataProvider("providePhp82Fixtures")]
#[RequiresPhp(">= 8.2")]
public function testPhp82Fixtures(string $name): void
{
$this->testFixture($name);
}
}
37 changes: 37 additions & 0 deletions tests/fixtures/orderedClassElements/actual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

class Example {
private string $var = "Error";
protected string $class = Error::class;
public string $laravel = "LaravelPaths";

public function test(): void
{
}

public static function testStatic(): void
{
}

use Castable;

public function test2(): void
{
}

protected function test3(): void
{
}

private function test4(): void
{
}

protected static function test5(): void
{
}

private static function test6(): void
{
}
}
40 changes: 40 additions & 0 deletions tests/fixtures/orderedClassElements/expected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

class Example
{
use Castable;

public string $laravel = "LaravelPaths";
protected string $class = Error::class;
private string $var = "Error";

public static function testStatic(): void
{
}

public function test(): void
{
}

public function test2(): void
{
}

protected static function test5(): void
{
}

protected function test3(): void
{
}

private static function test6(): void
{
}

private function test4(): void
{
}
}

0 comments on commit 7aecbaf

Please sign in to comment.