bkdotcom/PHPDebugConsole

View on GitHub
src/Debug/Plugin/Method/Count.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%

Replace this function name "count", since a "__construct" method has already been defined in this class.
Open

    public function count($label = null, $flags = 0)
Severity: Major
Found in src/Debug/Plugin/Method/Count.php by sonar-php

In PHP 4, any function with the same name as the nesting class was considered a class constructor. In PHP 5, this mechanism has been deprecated and the "__construct" method name should be used instead. If both styles are present in the same class, PHP 5 will treat the function named "__construct" as the class constructor.

This rule rule raises an issue for each method with the same name as the enclosing class.

Noncompliant Code Example

class Foo {
  function Foo(){...}
}

Compliant Solution

class Foo {
  function __construct(){...}
}

Define a constant instead of duplicating this literal "default" 3 times.
Open

    public function countReset($label = 'default', $flags = 0)
Severity: Critical
Found in src/Debug/Plugin/Method/Count.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.

There are no issues that match your filters.

Category
Status