Skip to content

Commit c21ca33

Browse files
committed
Moved static elements behind class constants
1 parent 35013d8 commit c21ca33

6 files changed

Lines changed: 51 additions & 49 deletions

File tree

src/FixerFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ public static function createFor(string $launchFile): Config
8787
self::$rules['ordered_class_elements']['order'] = [
8888
'use_trait', 'case',
8989
'constant_public', 'constant_protected', 'constant_private',
90+
'property_public_static', 'property_protected_static', 'property_private_static',
91+
'method_public_static', 'method_protected_static', 'method_private_static',
9092
'property_public', 'property_protected', 'property_private',
91-
'construct', 'destruct', 'magic', 'phpunit',
93+
'construct', 'phpunit', 'magic', 'destruct',
9294
'method_public', 'method_protected', 'method_private'
9395
];
9496

tests/Fixtures/FixerTestRunner.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323

2424
class FixerTestRunner
2525
{
26-
private array $fixers;
27-
28-
/**
29-
* @param FixerInterface[] $fixers
30-
*/
31-
public function __construct(array $fixers)
32-
{
33-
$this->fixers = $fixers;
34-
}
35-
3626
public static function withConfig(ConfigInterface $config): self
3727
{
3828
$fixerFactory = new FixerFactory();
@@ -47,6 +37,16 @@ public static function withConfig(ConfigInterface $config): self
4737
return new self($fixers);
4838
}
4939

40+
private array $fixers;
41+
42+
/**
43+
* @param FixerInterface[] $fixers
44+
*/
45+
public function __construct(array $fixers)
46+
{
47+
$this->fixers = $fixers;
48+
}
49+
5050
/**
5151
* @see Runner::fixFile()
5252
*

tests/Fixtures/code-samples/Fixer/expected-ClassOrder.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,44 @@ class ClassOrder
2121

2222
public static $publicStatic;
2323

24-
public ?string $publicValue = null;
25-
2624
protected static $staticValue;
2725

28-
private $value;
29-
30-
public function __construct()
26+
public static function instance(): self
3127
{
28+
return new self();
3229
}
3330

34-
public function setUpBeforeClass(): void
31+
public static function doPublicStatic(): void
3532
{
3633
}
3734

38-
private function setUp()
35+
protected static function doProtectedStatic(): int
3936
{
37+
return 1;
4038
}
4139

42-
public static function instance(): self
40+
public ?string $publicValue = null;
41+
42+
private $value;
43+
44+
public function __construct()
4345
{
44-
return new self();
4546
}
4647

47-
public static function doPublicStatic(): void
48+
public function setUpBeforeClass(): void
4849
{
4950
}
5051

51-
public function doPublic(): void
52+
private function setUp()
5253
{
5354
}
5455

55-
protected function doProtected()
56+
public function doPublic(): void
5657
{
5758
}
5859

59-
protected static function doProtectedStatic(): int
60+
protected function doProtected()
6061
{
61-
return 1;
6262
}
6363

6464
private function doPrivate()

tests/Fixtures/code-samples/Fixer/expected-ExampleClass.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ abstract class ExampleClass implements SomeInterface
2525
{
2626
public const CONSTANT = 'string';
2727

28+
/**
29+
* Creates from array.
30+
*
31+
* @param array $arr
32+
*
33+
* @return MyClass
34+
*/
35+
public static function fromArray(array $arr): self
36+
{
37+
return new self(implode('.', $arr));
38+
}
39+
40+
// Non-constructor method - no return type
41+
public static function withHelloString()
42+
{
43+
return new self('Hello World!');
44+
}
45+
2846
public array $field = [
2947
'key' => 1,
3048
'other' => 'value'
@@ -44,24 +62,6 @@ public function __construct(string $variable = '')
4462

4563
abstract public function somethingAbstract();
4664

47-
/**
48-
* Creates from array.
49-
*
50-
* @param array $arr
51-
*
52-
* @return MyClass
53-
*/
54-
public static function fromArray(array $arr): self
55-
{
56-
return new self(implode('.', $arr));
57-
}
58-
59-
// Non-constructor method - no return type
60-
public static function withHelloString()
61-
{
62-
return new self('Hello World!');
63-
}
64-
6565
public function getVariable()
6666
{
6767
return empty($this->variable)

tests/Fixtures/code-samples/Fixer/expected-MethodChainsClass.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class MethodChainsClass implements ArrayAccess
2020
{
2121
public const TEST = 1;
2222

23+
public static function withSomething(Name $variable)
24+
{
25+
return new self('string', $variable);
26+
}
27+
2328
protected $inheritedValues = [
2429
'key' => 'value',
2530
'longerKey' => 'another value'
@@ -36,11 +41,6 @@ public function __construct(string $something, Name $variable)
3641
$this->variable = $variable;
3742
}
3843

39-
public static function withSomething(Name $variable)
40-
{
41-
return new self('string', $variable);
42-
}
43-
4444
public function offsetExists($offset)
4545
{
4646
return array_key_exists($offset, $this->anotherVariable);

tests/Fixtures/code-samples/Fixer/expected-align.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class Some
3838
{
3939
public const VAR = '20';
4040
public const VARIABLE = 'foo bar baz';
41-
public $var = 10;
4241

4342
public static $stat;
4443
public static $fooBar;
44+
public $var = 10;
4545
protected $some = 23;
4646
protected $x = true;
4747
private $test = 22;

0 commit comments

Comments
 (0)