MainAero/yii2-gtm-widget

View on GitHub
tests/widget/GTMTest.php

Summary

Maintainability
A
0 mins
Test Coverage

Avoid using static access to class 'mainaero\yii\gtm\widget\GTM' in method 'testShouldReturnRenderedDataPushSnippet'.
Open

        GTM::widget(['type' => 'dataLayerPush'])
Severity: Minor
Found in tests/widget/GTMTest.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class 'mainaero\yii\gtm\widget\GTM' in method 'testShouldReturnEmptyStringIfNoDataLayerPushItems'.
Open

        $this->assertEquals('', GTM::widget(['type' => 'dataLayerPush']));
Severity: Minor
Found in tests/widget/GTMTest.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Define a constant instead of duplicating this literal "gtm_env" 6 times.
Open

        'gtm_env' => '&gtm_auth=<TOKEN>w&gtm_preview=<ENV_ID>&gtm_cookies_win=x',
Severity: Critical
Found in tests/widget/GTMTest.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "1A2B3CD" 6 times.
Open

        'gtm_id' => '1A2B3CD'
Severity: Critical
Found in tests/widget/GTMTest.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "&gtm_auth=<token>w&amp;gtm_preview=<env_id>&amp;gtm_cookies_win=x" 4 times.</env_id></token>
Open

        'gtm_env' => '&gtm_auth=<TOKEN>w&gtm_preview=<ENV_ID>&gtm_cookies_win=x',
Severity: Critical
Found in tests/widget/GTMTest.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "gtm_id" 6 times.
Open

        'gtm_id' => '1A2B3CD'
Severity: Critical
Found in tests/widget/GTMTest.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          $this->widget::widget(['type' => 'noscript'])
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          $this->renderer->renderPhpFile(
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 14 spaces but found 12
Open

            [
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          ]
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          ),
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          ),
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

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

      ];
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 8
Open

        ),
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

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

      );
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          'src/widget/views/dataLayerPush.php',
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 8
Open

        GTM::widget(['type' => 'dataLayerPush'])
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

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

      );
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 8 spaces but found 6
Open

      );
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 16 spaces but found 14
Open

              [
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          'src/widget/views/dataLayerPush.php',
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          [
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          $this->renderer->renderPhpFile(
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 14 spaces but found 12
Open

            'src/widget/views/noscript.php',
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 14 spaces but found 12
Open

            [
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 14 spaces but found 12
Open

            ]
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          [
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 14 spaces but found 12
Open

            ]
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

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

      );
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 16 spaces but found 14
Open

              ]
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

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

      ];
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          $this->widget->widget()
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 8 spaces but found 6
Open

      );
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 14 spaces but found 12
Open

            'src/widget/views/script.php',
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 10
Open

          ]
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 8 spaces but found 6
Open

      );
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 16 spaces but found 14
Open

              'src/widget/views/script.php',
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 8
Open

        $this->renderer->renderPhpFile(
Severity: Minor
Found in tests/widget/GTMTest.php by phpcodesniffer

There are no issues that match your filters.

Category
Status