MainAero/yii2-gtm-widget

View on GitHub
src/widget/GTM.php

Summary

Maintainability
A
0 mins
Test Coverage

Add curly braces around the nested statement(s).
Open

        if ($this->type == self::TYPE_PUSH)
Severity: Critical
Found in src/widget/GTM.php by sonar-php

While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

Noncompliant Code Example

if (condition)  // Noncompliant
  executeSomething();

Compliant Solution

if (condition) {
  executeSomething();
}

See

  • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
  • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
  • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

Add curly braces around the nested statement(s).
Open

      if (empty($dataLayerPushItems))
Severity: Critical
Found in src/widget/GTM.php by sonar-php

While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

Noncompliant Code Example

if (condition)  // Noncompliant
  executeSomething();

Compliant Solution

if (condition) {
  executeSomething();
}

See

  • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
  • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
  • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

Add curly braces around the nested statement(s).
Open

        if ($this->paramMissing($params))
Severity: Critical
Found in src/widget/GTM.php by sonar-php

While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

Noncompliant Code Example

if (condition)  // Noncompliant
  executeSomething();

Compliant Solution

if (condition) {
  executeSomething();
}

See

  • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
  • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
  • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

Inline control structures are not allowed
Open

        if ($this->paramMissing($params))
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Inline control structures are not allowed
Open

      if (empty($dataLayerPushItems))
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Inline control structures are not allowed
Open

        if ($this->type == self::TYPE_PUSH)
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Line indented incorrectly; expected at least 8 spaces, found 6
Open

      return $this->render($this->type, ['dataLayerPushItems' => $dataLayerPushItems]);
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Line indented incorrectly; expected at least 8 spaces, found 6
Open

      $session = Yii::$app->getSession();
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Opening brace should be on a new line
Open

    private function runPush() : String {
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Line indented incorrectly; expected at least 8 spaces, found 6
Open

      $dataLayerPushItems = $session->get(self::SESSION_KEY) ?? [];
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Line indented incorrectly; expected at least 8 spaces, found 6
Open

      if (empty($dataLayerPushItems))
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

Line indented incorrectly; expected at least 8 spaces, found 6
Open

      $session->remove(self::SESSION_KEY);
Severity: Minor
Found in src/widget/GTM.php by phpcodesniffer

There are no issues that match your filters.

Category
Status