Commit 9b63c4a3 authored by Jonathan Smith's avatar Jonathan Smith Committed by Klaus Purer
Browse files

fix(FunctionTriggerError): Cater for sprintf() inside @trigger_error() call (#3049093)

parent c1693696
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -69,11 +69,11 @@ class FunctionTriggerErrorSniff extends FunctionCall
        // Get the first argument passed to trigger_error().
        $argument = $this->getArgument(1);

        // Apart from an optional __NAMESPACE__ concatenated at the start of the
        // message, the text should be in one string without any further
        // concatenations. This means that in all cases the 'end' content will
        // contain the message text to be checked.
        $message_text = $tokens[$argument['end']]['content'];
        // Extract the message text to check. Using findNext() will allow for
        // an optional __NAMESPACE__ concatenated at the start and also cater
        // for function calls such as sprintf() inside the message.
        $message_position = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $argument['start']);
        $message_text     = $tokens[$message_position]['content'];

        // The standard format for @trigger_error() is:
        // %thing% is deprecated in %in-version%. %extra-info%. See %cr-link%
+5 −7
Original line number Diff line number Diff line
@@ -18,8 +18,10 @@
@trigger_error("\Drupal\Some\Class\Foo is deprecated in drupal:8.11.0. Use \Drupal\Foo. See https://www.drupal.org/project/drupal/issues/2908490", E_User_Deprecated);
// Alternative syntax for contrib project and issue url.
@trigger_error('Function foo_bar() is deprecated in my_module:8.x-2.0. Use bar_baz() instead. See https://www.drupal.org/project/my_module/issues/2908490', E_USER_DEPRECATED);
// Cater for sprintf inside the message.
@trigger_error(sprintf('Function %s is deprecated in drupal:8.5.0. Use foo() instead. See http://www.drupal.org/project/my_module/issues/123', $settings), E_USER_DEPRECATED);

// Fails on general layout.
// ERRORS on general layout.
// Wrong first part - missing word.
@trigger_error('drupal_set_message() is deprecated Drupal:8.5.0. It will be removed from Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
// Wrong first part - bad spacing.
@@ -32,9 +34,7 @@
@trigger_error('drupal_set_message() is deprecated in Drupal:8.5.0. See https://www.drupal.org/node/2774931', E_User_Deprecated);
// String would be OK but is in more than one part.
@trigger_error('drupal_set_message() is deprecated in Drupal:8.5.0. ' . 'It will be removed from Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);

// Fails on version.
// Version with only one component.
// WARNINGS for version. Version with only one component.
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in drupal:8. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
// Version with only two components.
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in drupal:8.6. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
@@ -50,9 +50,7 @@
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in project:182.x-2.0. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
// Wrong case for Project.
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in Project:8.6-2.x. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED);

// Fails on 'see' url.
// Incorrect see url - no http.
// WARNINGS for 'see' url. Incorrect see url - no http.
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in drupal:8.6.0. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See www.drupal.org/node/2908490', E_USER_DEPRECATED);
// Incorrect see url - extra text before http.
@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in drupal:8.6.0. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See this http://www.drupal.org/node/2908490', E_USER_DEPRECATED);
+2 −2
Original line number Diff line number Diff line
@@ -18,12 +18,12 @@ class FunctionTriggerErrorUnitTest extends CoderSniffUnitTest
    public function getErrorList($testFile = NULL)
    {
        return array(
            24 => 1,
            26 => 1,
            28 => 1,
            30 => 1,
            32 => 1,
            34 => 1,
            36 => 1,
        );

    }//end getErrorList()
@@ -48,12 +48,12 @@ class FunctionTriggerErrorUnitTest extends CoderSniffUnitTest
            48 => 1,
            50 => 1,
            52 => 1,
            54 => 1,
            56 => 1,
            58 => 1,
            60 => 1,
            62 => 1,
            64 => 1,
            66 => 1,
        );

    }//end getWarningList()