Skip to content

Commit

Permalink
Fix priorities (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Oct 6, 2021
1 parent 479c935 commit 873200c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
![Tests](https://img.shields.io/badge/tests-2855-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-2867-brightgreen.svg)
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)

[![CI Status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions)
Expand Down
3 changes: 2 additions & 1 deletion src/Fixer/MultilinePromotedPropertiesFixer.php
Expand Up @@ -51,11 +51,12 @@ public function setWhitespacesConfig(WhitespacesFixerConfig $config): void
}

/**
* Must run before BracesFixer.
* Must run after PromotedConstructorPropertyFixer.
*/
public function getPriority(): int
{
return 0;
return 36;
}

public function isCandidate(Tokens $tokens): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/PromotedConstructorPropertyFixer.php
Expand Up @@ -50,7 +50,7 @@ public function __construct(string $bar) {
}

/**
* Must run before ClassAttributesSeparationFixer, MultilinePromotedPropertiesFixer.
* Must run before BracesFixer, ClassAttributesSeparationFixer, MultilinePromotedPropertiesFixer, NoExtraBlankLinesFixer, NoUnusedImportsFixer.
*/
public function getPriority(): int
{
Expand Down
83 changes: 81 additions & 2 deletions tests/PriorityTest.php
Expand Up @@ -241,6 +241,26 @@ function provideFooCases() {}
*******/',
];

$multilinePromotedPropertiesFixer = new CustomFixer\MultilinePromotedPropertiesFixer();
$multilinePromotedPropertiesFixer->setWhitespacesConfig(new WhitespacesFixerConfig());
yield [
$multilinePromotedPropertiesFixer,
new Fixer\Basic\BracesFixer(),
'<?php class Foo
{
public function __construct(
private int $x
) {
}
}',
'<?php class Foo
{
public function __construct(private int $x)
{
}
}',
];

yield [
new CustomFixer\NoCommentedOutCodeFixer(),
new Fixer\Whitespace\NoExtraBlankLinesFixer(),
Expand Down Expand Up @@ -690,6 +710,26 @@ function foo($x, $y) {}
',
];

yield [
new CustomFixer\PromotedConstructorPropertyFixer(),
new Fixer\Basic\BracesFixer(),
'<?php class Foo
{
public function __construct(private int $x)
{
}
}',
'<?php class Foo
{
private int $x;
public function __construct(int $x)
{
$this->x = $x;
}
}',
];

yield [
new CustomFixer\PromotedConstructorPropertyFixer(),
new Fixer\ClassNotation\ClassAttributesSeparationFixer(),
Expand All @@ -713,8 +753,6 @@ public function __construct(int $x, int $y) {
',
];

$multilinePromotedPropertiesFixer = new CustomFixer\MultilinePromotedPropertiesFixer();
$multilinePromotedPropertiesFixer->setWhitespacesConfig(new WhitespacesFixerConfig());
yield [
new CustomFixer\PromotedConstructorPropertyFixer(),
$multilinePromotedPropertiesFixer,
Expand All @@ -735,6 +773,47 @@ public function __construct(int $x, int $y) {
}',
];

yield [
new CustomFixer\PromotedConstructorPropertyFixer(),
new Fixer\Whitespace\NoExtraBlankLinesFixer(),
'<?php class Foo {
public function __construct(private int $x, private int $y) {
}
}',
'<?php class Foo {
private int $x;
private int $y;
public function __construct(int $x, int $y) {
$this->x = $x;
$this->y = $y;
}
}',
];

yield [
new CustomFixer\PromotedConstructorPropertyFixer(),
new Fixer\Import\NoUnusedImportsFixer(),
'<?php namespace Foo;
class Test {
public function __construct(private int $x) {
}
}
',
'<?php namespace Foo;
use Bar\Baz;
class Test {
/** @var Baz[] */
private array $x;
public function __construct(int $x) {
$this->x = $x;
}
}
',
];

yield [
new Fixer\FunctionNotation\SingleLineThrowFixer(),
new CustomFixer\NoSuperfluousConcatenationFixer(),
Expand Down

0 comments on commit 873200c

Please sign in to comment.