Skip to content

Commit

Permalink
Add option allowOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 3, 2019
1 parent da72d36 commit 5075df8
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
class BooleanOperatorPlacementSniff implements Sniff
{

/**
* Used to restrict the placement of the boolean operator
* Allowed value are 'first' or 'last'
*
* @var string|null
*/
public $allowOnly = null;


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

$operator = $parenOpener;
$position = null;
$position = $this->getDefaultPosition();
$error = false;
$operators = [];

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


/**
* Default to null value if the option is not 'first' or 'last'
*
* @return string|null
*/
private function getDefaultPosition()
{
switch ($this->allowOnly) {
case 'first':
case 'last':
return $this->allowOnly;
default:
return null;
}

}//end getDefaultPosition()


}//end class

0 comments on commit 5075df8

Please sign in to comment.