Skip to content

Commit

Permalink
PhpdocOrderByValueFixer - Allow sorting of throws annotations by value
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored and keradus committed Dec 23, 2020
1 parent 1b81c27 commit 4ec00e9
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/rules/phpdoc/phpdoc_order_by_value.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Configuration

List of annotations to order, e.g. ``["covers"]``.

Allowed values: a subset of ``['author', 'covers', 'coversNothing', 'dataProvider', 'depends', 'group', 'internal', 'requires', 'uses']``
Allowed values: a subset of ``['author', 'covers', 'coversNothing', 'dataProvider', 'depends', 'group', 'internal', 'requires', 'throws', 'uses']``

Default value: ``['covers']``

Expand Down
1 change: 1 addition & 0 deletions src/Fixer/Phpdoc/PhpdocOrderByValueFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ protected function createConfigurationDefinition()
'group',
'internal',
'requires',
'throws',
'uses',
];

Expand Down
139 changes: 139 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocOrderByValueFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,145 @@ public function testMe() {}
];
}

/**
* @param string $expected
* @param null|string $input
*
* @dataProvider provideFixWithThrowsCases
*/
public function testFixWithThrows($expected, $input = null)
{
$this->fixer->configure([
'annotations' => [
'throws',
],
]);

$this->doTest($expected, $input);
}

public function provideFixWithThrowsCases()
{
return [
'skip on 1 or 0 occurrences' => [
'<?php
class Foo {
/**
* @throws Bar
* @params bool $bool
* @return void
*/
public function bar() {}
/**
* @params bool $bool
* @return void
*/
public function baz() {}
}
',
],
'base case' => [
'<?php
class Foo
{
/**
* @throws Bar
* @throws Baz
*/
public function bar() {}
}
',
'<?php
class Foo
{
/**
* @throws Baz
* @throws Bar
*/
public function bar() {}
}
',
],
'preserve positions if other docblock parts are present' => [
'<?php
class Foo
{
/**
* Comment 1
* @throws Bar
* Comment 3
* @throws Baz
* Comment 2
*/
public function bar() {}
}
',
'<?php
class Foo
{
/**
* Comment 1
* @throws Baz
* Comment 2
* @throws Bar
* Comment 3
*/
public function bar() {}
}
',
],
'case-insensitive' => [
'<?php
class Foo
{
/**
* @throws A
* @throws b
* @throws C
*/
public function bar() {}
}
',
'<?php
class Foo
{
/**
* @throws b
* @throws C
* @throws A
*/
public function bar() {}
}
',
],
'fully-qualified' => [
'<?php
class Foo
{
/**
* @throws \Bar\Baz\Qux
* @throws Bar
* @throws Foo
*/
public function bar() {}
}
',
'<?php
class Foo
{
/**
* @throws Bar
* @throws \Bar\Baz\Qux
* @throws Foo
*/
public function bar() {}
}
',
],
];
}

/**
* @param string $expected
* @param null|string $input
Expand Down

0 comments on commit 4ec00e9

Please sign in to comment.