Skip to content

Commit

Permalink
Add ordered_class_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Aug 1, 2024
1 parent 0e4c5d7 commit a9c8d42
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/RuleSet/Sets/Relax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/RuleSet/Sets/RelaxPlus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
Expand Down
33 changes: 33 additions & 0 deletions tests/Fixtures/Ruleset/relax-commonbox_actual.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
57 changes: 57 additions & 0 deletions tests/Fixtures/Ruleset/relax-commonbox_expected.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
33 changes: 33 additions & 0 deletions tests/Fixtures/Ruleset/relaxplus_actual.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
57 changes: 57 additions & 0 deletions tests/Fixtures/Ruleset/relaxplus_expected.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down

0 comments on commit a9c8d42

Please sign in to comment.