diff --git a/src/RuleSet/Sets/Relax.php b/src/RuleSet/Sets/Relax.php index 80dd0fd..3e1aed4 100644 --- a/src/RuleSet/Sets/Relax.php +++ b/src/RuleSet/Sets/Relax.php @@ -36,6 +36,7 @@ public function mainRules(): array 'no_useless_nullsafe_operator' => true, 'numeric_literal_separator' => true, 'operator_linebreak' => ['only_booleans' => true], + 'ordered_class_elements' => ['order' => ['use_trait']], 'ordered_types' => ['sort_algorithm' => 'none'], 'phpdoc_param_order' => true, 'phpdoc_trim_consecutive_blank_line_separation' => true, diff --git a/src/RuleSet/Sets/RelaxPlus.php b/src/RuleSet/Sets/RelaxPlus.php index b9d2e18..c5780da 100644 --- a/src/RuleSet/Sets/RelaxPlus.php +++ b/src/RuleSet/Sets/RelaxPlus.php @@ -37,6 +37,11 @@ public function mainRules(): array // Control Structure 'class_definition' => ['single_line' => true, 'space_before_parenthesis' => true], 'no_superfluous_elseif' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', 'case', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'destruct', 'magic', 'phpunit', + ], + ], // Cleanup 'phpdoc_no_alias_tag' => ['replacements' => ['type' => 'var', 'link' => 'see']], diff --git a/tests/Fixtures/Ruleset/relax-commonbox_actual.php b/tests/Fixtures/Ruleset/relax-commonbox_actual.php index 928bf8c..e921dd9 100644 --- a/tests/Fixtures/Ruleset/relax-commonbox_actual.php +++ b/tests/Fixtures/Ruleset/relax-commonbox_actual.php @@ -95,6 +95,39 @@ interface Bar extends $baz ) {}; +/** + * ordered_class_elements + */ +final class OrderedClassElements +{ + use TraiB; + use TraiA; + protected static $protStatProp; + const C1 = 1; + const C2 = 2; + public static $pubStatProp1; + public $pubProp1; + protected $protProp; + var $pubProp2; + private static $privStatProp; + private $privProp; + public static $pubStatProp2; + public $pubProp3; + protected function __construct() {} + private static function privStatFunc() {} + public function pubFunc1() {} + public function __toString() {} + protected function protFunc() {} + function pubFunc2() {} + public static function pubStatFunc1() {} + public function pubFunc3() {} + static function pubStatFunc2() {} + private function privFunc() {} + public static function pubStatFunc3() {} + protected static function protStatFunc() {} + public function __destruct() {} +} + /** * ordered_interfaces */ diff --git a/tests/Fixtures/Ruleset/relax-commonbox_expected.php b/tests/Fixtures/Ruleset/relax-commonbox_expected.php index df0fcf3..dd9ef7e 100644 --- a/tests/Fixtures/Ruleset/relax-commonbox_expected.php +++ b/tests/Fixtures/Ruleset/relax-commonbox_expected.php @@ -98,6 +98,63 @@ interface Bar extends $baz, ) {}; +/** + * ordered_class_elements + */ +final class OrderedClassElements +{ + use TraiA; + use TraiB; + + protected static $protStatProp; + + const C1 = 1; + + const C2 = 2; + + public static $pubStatProp1; + + public $pubProp1; + + protected $protProp; + + public $pubProp2; + + private static $privStatProp; + + private $privProp; + + public static $pubStatProp2; + + public $pubProp3; + + protected function __construct() {} + + private static function privStatFunc() {} + + public function pubFunc1() {} + + public function __toString() {} + + protected function protFunc() {} + + public function pubFunc2() {} + + public static function pubStatFunc1() {} + + public function pubFunc3() {} + + public static function pubStatFunc2() {} + + private function privFunc() {} + + public static function pubStatFunc3() {} + + protected static function protStatFunc() {} + + public function __destruct() {} +} + /** * ordered_interfaces */ diff --git a/tests/Fixtures/Ruleset/relaxplus_actual.php b/tests/Fixtures/Ruleset/relaxplus_actual.php index 0fe5dda..038d94d 100644 --- a/tests/Fixtures/Ruleset/relaxplus_actual.php +++ b/tests/Fixtures/Ruleset/relaxplus_actual.php @@ -95,6 +95,39 @@ interface Bar extends $baz ) {}; +/** + * ordered_class_elements + */ +final class OrderedClassElements +{ + use TraiB; + use TraiA; + protected static $protStatProp; + const C1 = 1; + const C2 = 2; + public static $pubStatProp1; + public $pubProp1; + protected $protProp; + var $pubProp2; + private static $privStatProp; + private $privProp; + public static $pubStatProp2; + public $pubProp3; + protected function __construct() {} + private static function privStatFunc() {} + public function pubFunc1() {} + public function __toString() {} + protected function protFunc() {} + function pubFunc2() {} + public static function pubStatFunc1() {} + public function pubFunc3() {} + static function pubStatFunc2() {} + private function privFunc() {} + public static function pubStatFunc3() {} + protected static function protStatFunc() {} + public function __destruct() {} +} + class MyTest extends \PhpUnit\FrameWork\TestCase { /** diff --git a/tests/Fixtures/Ruleset/relaxplus_expected.php b/tests/Fixtures/Ruleset/relaxplus_expected.php index 3243e00..d984ebf 100644 --- a/tests/Fixtures/Ruleset/relaxplus_expected.php +++ b/tests/Fixtures/Ruleset/relaxplus_expected.php @@ -85,6 +85,63 @@ interface Bar extends Bar, BarBaz, FooBarBaz {} $space_before_parenthesis = new class {}; $inline_constructor_arguments = new class ($bar, $baz) {}; +/** + * ordered_class_elements + */ +final class OrderedClassElements +{ + use TraiA; + use TraiB; + + const C1 = 1; + + const C2 = 2; + + public static $pubStatProp1; + + public $pubProp1; + + public $pubProp2; + + public static $pubStatProp2; + + public $pubProp3; + + protected static $protStatProp; + + protected $protProp; + + private static $privStatProp; + + private $privProp; + + protected function __construct() {} + + public function __destruct() {} + + public function __toString() {} + + private static function privStatFunc() {} + + public function pubFunc1() {} + + protected function protFunc() {} + + public function pubFunc2() {} + + public static function pubStatFunc1() {} + + public function pubFunc3() {} + + public static function pubStatFunc2() {} + + private function privFunc() {} + + public static function pubStatFunc3() {} + + protected static function protStatFunc() {} +} + class MyTest extends \PhpUnit\FrameWork\TestCase { /**