Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit f611ae9

Browse files
Normalise parentheses (#39)
* Normalise parentheses * Not meant * Add simple case
1 parent ccd9d28 commit f611ae9

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

src/Libero/ruleset.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
2828
<rule ref="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
2929
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
30+
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
31+
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
3032
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
3133
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
3234
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
@@ -47,6 +49,11 @@
4749
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
4850
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
4951
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
52+
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses">
53+
<properties>
54+
<property name="ignoreComplexTernaryConditions" value="true"/>
55+
</properties>
56+
</rule>
5057
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
5158
<properties>
5259
<property name="newlinesCountAfterDeclare" value="2"/>

tests/cases/php/parentheses

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---DESCRIPTION---
2+
Language constructs must be used without parentheses
3+
---CONTENTS---
4+
<?php
5+
6+
declare(strict_types=1);
7+
8+
require('foo.php');
9+
10+
echo('bar');
11+
12+
foreach ([] as $value) {
13+
break (1);
14+
}
15+
16+
$baz = function () {
17+
yield('baz');
18+
return('qux');
19+
};
20+
21+
die();
22+
23+
---FIXED---
24+
<?php
25+
26+
declare(strict_types=1);
27+
28+
require 'foo.php';
29+
30+
echo 'bar';
31+
32+
foreach ([] as $value) {
33+
break 1;
34+
}
35+
36+
$baz = function () {
37+
yield 'baz';
38+
return 'qux';
39+
};
40+
41+
die;
42+
43+
---

tests/cases/php/parentheses-new

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---DESCRIPTION---
2+
New instances must use parentheses
3+
---CONTENTS---
4+
<?php
5+
6+
declare(strict_types=1);
7+
8+
new Foo;
9+
10+
---FIXED---
11+
<?php
12+
13+
declare(strict_types=1);
14+
15+
new Foo();
16+
17+
---
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---DESCRIPTION---
2+
Parentheses must not be used unnecessarily
3+
---CONTENTS---
4+
<?php
5+
6+
declare(strict_types=1);
7+
8+
$foo = ('bar');
9+
$baz = ($qux !== null) ? true : false;
10+
$quux = ($quuz) ? 1 : 0;
11+
$corge = (true || false) ? 0 : 1;
12+
13+
switch ($grault) {
14+
case (true):
15+
case (false):
16+
return $garply / (100 + $waldo);
17+
}
18+
19+
---FIXED---
20+
<?php
21+
22+
declare(strict_types=1);
23+
24+
$foo = 'bar';
25+
$baz = $qux !== null ? true : false;
26+
$quux = $quuz ? 1 : 0;
27+
$corge = (true || false) ? 0 : 1;
28+
29+
switch ($grault) {
30+
case true:
31+
case false:
32+
return $garply / (100 + $waldo);
33+
}
34+
35+
---

0 commit comments

Comments
 (0)