Skip to content

Commit 6afa4bd

Browse files
committed
QA: minor code tweaks for memory usage
As discussed in PR 1356 in comment #1356 (comment) and originally discovered and addressed in squizlabs/PHP_CodeSniffer 2273
1 parent f4e1748 commit 6afa4bd

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/Files/File.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,8 +1899,9 @@ public function getMemberProperties(int $stackPtr)
18991899

19001900
// Make sure it's not a method parameter.
19011901
if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
1902-
$parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
1903-
$deepestOpen = array_pop($parenthesis);
1902+
$parentheses = $this->tokens[$stackPtr]['nested_parenthesis'];
1903+
$parentheses = array_keys($parentheses);
1904+
$deepestOpen = array_pop($parentheses);
19041905
if ($deepestOpen > $ptr
19051906
&& isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
19061907
&& $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,9 @@ public function process(File $phpcsFile, int $stackPtr)
754754
) {
755755
$isMethodPrefix = true;
756756
if (isset($tokens[$checkToken]['nested_parenthesis']) === true) {
757-
$parenthesis = array_keys($tokens[$checkToken]['nested_parenthesis']);
758-
$deepestOpen = array_pop($parenthesis);
757+
$parentheses = $tokens[$checkToken]['nested_parenthesis'];
758+
$parentheses = array_keys($parentheses);
759+
$deepestOpen = array_pop($parentheses);
759760
if (isset($tokens[$deepestOpen]['parenthesis_owner']) === true
760761
&& $tokens[$tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
761762
) {

src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ public function process(File $phpcsFile, int $stackPtr)
136136

137137
$lastBracket = false;
138138
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
139-
$parenthesis = array_reverse($tokens[$stackPtr]['nested_parenthesis'], true);
140-
foreach ($parenthesis as $bracket => $endBracket) {
139+
$parentheses = $tokens[$stackPtr]['nested_parenthesis'];
140+
$parentheses = array_reverse($parentheses, true);
141+
foreach ($parentheses as $bracket => $endBracket) {
141142
$prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($bracket - 1), null, true);
142143
$prevCode = $tokens[$prevToken]['code'];
143144

src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ protected function isOperator(File $phpcsFile, int $stackPtr)
350350
// Skip declare statements.
351351
if ($tokens[$stackPtr]['code'] === T_EQUAL) {
352352
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
353-
$parenthesis = array_keys($tokens[$stackPtr]['nested_parenthesis']);
354-
$bracket = array_pop($parenthesis);
353+
$parentheses = $tokens[$stackPtr]['nested_parenthesis'];
354+
$parentheses = array_keys($parentheses);
355+
$bracket = array_pop($parentheses);
355356
if (isset($tokens[$bracket]['parenthesis_owner']) === true) {
356357
$function = $tokens[$bracket]['parenthesis_owner'];
357358
if ($tokens[$function]['code'] === T_FUNCTION

0 commit comments

Comments
 (0)