Unverified Commit 38328fc7 authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

fix(GlobalFunction): Fix Drupal 7 false positives (#3056538)

parent 4d110e46
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@ class GlobalFunctionSniff implements Sniff
    {
        $tokens = $phpcsFile->getTokens();

        // Only run this sniff on Drupal 8+.
        if (Project::getCoreVersion($phpcsFile) < 8) {
            return;
        }

        // We are only interested in function calls, which are not in the global
        // scope.
        if (isset($this->functions[$tokens[$stackPtr]['content']]) === false
+3 −2
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class GlobalFunctionUnitTest extends CoderSniffUnitTest
    protected function getWarningList($testFile=null)
    {
        switch ($testFile) {
        case 'GlobalFunctionUnitTest.inc':
        case 'TestForm.php':
            return [
                6 => 1,
                8 => 1,
@@ -70,11 +70,12 @@ class GlobalFunctionUnitTest extends CoderSniffUnitTest
    protected function getTestFiles($testFileBase)
    {
        return [
            __DIR__.'/GlobalFunctionUnitTest.inc',
            __DIR__.'/src/example.module',
            __DIR__.'/src/ExampleClass.php',
            __DIR__.'/src/ExampleClassWithDependencyInjection.php',
            __DIR__.'/src/ExampleService.php',
            __DIR__.'/src/TestForm.php',
            __DIR__.'/drupal7/ExampleMigration.php',
        ];

    }//end getTestFiles()
+28 −0
Original line number Diff line number Diff line
<?php

/**
 * A class from Drupal 7 that should not throw errors.
 */
class ExampleMigration extends ExampleMigrateBase {

  /**
   * {@inheritdoc}
   */
  public function __construct($arguments) {
    parent::__construct($arguments);
    $this->description = t('Import users from the CSV.');
    $columns = [
      ['uuid', t('UUID')],
      ['name', t('Username')],
      ['pass', t('User password')],
      ['email', t('User email')],
      ['role', t('User role')],
      ['site', t('Site')],
      ['first_name', t('First name')],
      ['last_name', t('Last name')],
      ['phone', t('Phone')],
      ['status', t('Status')],
    ];
  }

}
+2 −0
Original line number Diff line number Diff line
name = Test
core = 7.x
Loading