Commit 9514bd49 authored by Klaus Purer's avatar Klaus Purer
Browse files

fix(Array): Fix false positive for closure defined inside an array (#3029013)

parent a6722cc6
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -180,8 +180,16 @@ class ArraySniff implements Sniff
                // in other sniffs. If the conditions of a token are different it
                // means that it is in a different nesting level.
                if ($tokens[$newLineStart]['conditions'] !== $tokens[$stackPtr]['conditions']) {
                    // Jump to the end of the closure.
                    $conditionKeys = array_keys($tokens[$newLineStart]['conditions']);
                    $closureToken  = end($conditionKeys);
                    if (isset($tokens[$closureToken]['scope_closer']) === true) {
                        $newLineStart = $tokens[$closureToken]['scope_closer'];
                        $currentLine  = $tokens[$closureToken]['line'];
                    } else {
                        $currentLine++;
                    }
                }
            }//end while

            if ($newLineStart === $tokens[$stackPtr][$parenthesisCloser]) {
+15 −0
Original line number Diff line number Diff line
@@ -109,3 +109,18 @@ $backend->expects($this->exactly(1))
      'module_handler_test_missing' => [],
    ]]]
  ));

/**
 * Nested closure in an array should not throw errors.
 */
function mymodule_libraries_info() {
  $libraries['some-library'] = array(
    'xautoload' => function ($adapter) {
      /** @var \Drupal\xautoload\Adapter\LocalDirectoryAdapter $adapter */
      // Scan sites/all/libraries/some-library/composer.json to look for
      // autoload information.
      $adapter->composerJson('composer.json');
    },
  );
  return $libraries;
}
+15 −0
Original line number Diff line number Diff line
@@ -116,3 +116,18 @@ $backend->expects($this->exactly(1))
      ],
    ]
  ));

/**
 * Nested closure in an array should not throw errors.
 */
function mymodule_libraries_info() {
  $libraries['some-library'] = array(
    'xautoload' => function ($adapter) {
      /** @var \Drupal\xautoload\Adapter\LocalDirectoryAdapter $adapter */
      // Scan sites/all/libraries/some-library/composer.json to look for
      // autoload information.
      $adapter->composerJson('composer.json');
    },
  );
  return $libraries;
}