From 5075df822abbe66046a8135fd75214dbd64c065b Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 3 Nov 2019 11:31:58 +0100 Subject: [PATCH] Add option allowOnly --- .../BooleanOperatorPlacementSniff.php | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Standards/PSR12/Sniffs/ControlStructures/BooleanOperatorPlacementSniff.php b/src/Standards/PSR12/Sniffs/ControlStructures/BooleanOperatorPlacementSniff.php index 758ba41247..95e62bc23b 100644 --- a/src/Standards/PSR12/Sniffs/ControlStructures/BooleanOperatorPlacementSniff.php +++ b/src/Standards/PSR12/Sniffs/ControlStructures/BooleanOperatorPlacementSniff.php @@ -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. @@ -67,7 +75,7 @@ public function process(File $phpcsFile, $stackPtr) ]; $operator = $parenOpener; - $position = null; + $position = $this->getDefaultPosition(); $error = false; $operators = []; @@ -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