Skip to content

Commit

Permalink
Merge branch 'php-8.0/pear-objectoperatorindent-support-nullsafe-oper…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Sep 9, 2020
2 parents bf1d2b2 + 460f212 commit 69a28ec
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Standards/PEAR/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ class ObjectOperatorIndentSniff implements Sniff
*/
public $multilevel = false;

/**
* Tokens to listen for.
*
* @var array
*/
private $targets = [
T_OBJECT_OPERATOR,
T_NULLSAFE_OBJECT_OPERATOR,
];


/**
* Returns an array of tokens this test wants to listen for.
Expand All @@ -37,7 +47,7 @@ class ObjectOperatorIndentSniff implements Sniff
*/
public function register()
{
return [T_OBJECT_OPERATOR];
return $this->targets;

}//end register()

Expand All @@ -57,14 +67,14 @@ public function process(File $phpcsFile, $stackPtr)

// Make sure this is the first object operator in a chain of them.
$start = $phpcsFile->findStartOfStatement($stackPtr);
$prev = $phpcsFile->findPrevious(T_OBJECT_OPERATOR, ($stackPtr - 1), $start);
$prev = $phpcsFile->findPrevious($this->targets, ($stackPtr - 1), $start);
if ($prev !== false) {
return;
}

// Make sure this is a chained call.
$end = $phpcsFile->findEndOfStatement($stackPtr);
$next = $phpcsFile->findNext(T_OBJECT_OPERATOR, ($stackPtr + 1), $end);
$next = $phpcsFile->findNext($this->targets, ($stackPtr + 1), $end);
if ($next === false) {
// Not a chained call.
return;
Expand Down Expand Up @@ -179,7 +189,7 @@ public function process(File $phpcsFile, $stackPtr)
}//end if

$next = $phpcsFile->findNext(
T_OBJECT_OPERATOR,
$this->targets,
($next + 1),
null,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,27 @@ $rootNode
->five();

// phpcs:set PEAR.WhiteSpace.ObjectOperatorIndent multilevel false

$object
?->setBar($foo)
?->setFoo($bar);

$someObject?->someFunction("some", "parameter")
->someOtherFunc(23, 42)?->
someOtherFunc2($one, $two)

->someOtherFunc3(23, 42)
?->andAThirdFunction();

// phpcs:set PEAR.WhiteSpace.ObjectOperatorIndent multilevel true
$object
?->setBar($foo)
?->setFoo($bar);

$someObject?->someFunction("some", "parameter")
->someOtherFunc(23, 42)
?->someOtherFunc2($one, $two)

->someOtherFunc3(23, 42)
?->andAThirdFunction();
// phpcs:set PEAR.WhiteSpace.ObjectOperatorIndent multilevel false
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,27 @@ $rootNode
->five();

// phpcs:set PEAR.WhiteSpace.ObjectOperatorIndent multilevel false

$object
?->setBar($foo)
?->setFoo($bar);

$someObject?->someFunction("some", "parameter")
->someOtherFunc(23, 42)
?->someOtherFunc2($one, $two)

->someOtherFunc3(23, 42)
?->andAThirdFunction();

// phpcs:set PEAR.WhiteSpace.ObjectOperatorIndent multilevel true
$object
?->setBar($foo)
?->setFoo($bar);

$someObject?->someFunction("some", "parameter")
->someOtherFunc(23, 42)
?->someOtherFunc2($one, $two)

->someOtherFunc3(23, 42)
?->andAThirdFunction();
// phpcs:set PEAR.WhiteSpace.ObjectOperatorIndent multilevel false
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function getErrorList()
82 => 1,
95 => 1,
103 => 1,
119 => 2,
122 => 1,
131 => 1,
134 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 69a28ec

Please sign in to comment.