Skip to content

Commit 5075df8

Browse files
Add option allowOnly
1 parent da72d36 commit 5075df8

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/Standards/PSR12/Sniffs/ControlStructures/BooleanOperatorPlacementSniff.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
class BooleanOperatorPlacementSniff implements Sniff
1717
{
1818

19+
/**
20+
* Used to restrict the placement of the boolean operator
21+
* Allowed value are 'first' or 'last'
22+
*
23+
* @var string|null
24+
*/
25+
public $allowOnly = null;
26+
1927

2028
/**
2129
* Returns an array of tokens this test wants to listen for.
@@ -67,7 +75,7 @@ public function process(File $phpcsFile, $stackPtr)
6775
];
6876

6977
$operator = $parenOpener;
70-
$position = null;
78+
$position = $this->getDefaultPosition();
7179
$error = false;
7280
$operators = [];
7381

@@ -183,4 +191,22 @@ public function process(File $phpcsFile, $stackPtr)
183191
}//end process()
184192

185193

194+
/**
195+
* Default to null value if the option is not 'first' or 'last'
196+
*
197+
* @return string|null
198+
*/
199+
private function getDefaultPosition()
200+
{
201+
switch ($this->allowOnly) {
202+
case 'first':
203+
case 'last':
204+
return $this->allowOnly;
205+
default:
206+
return null;
207+
}
208+
209+
}//end getDefaultPosition()
210+
211+
186212
}//end class

0 commit comments

Comments
 (0)