wol-soft/php-performance-timer

View on GitHub
src/Timer.php

Summary

Maintainability
A
0 mins
Test Coverage
A
94%

The method throw uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            error_log("PerformanceTimer error: " . $exception->getMessage());
        }
Severity: Minor
Found in src/Timer.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Define a constant instead of duplicating this literal "profileNamespace" 4 times.
Open

        'profileNamespace' => '',
Severity: Critical
Found in src/Timer.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 "outputHandler" 4 times.
Open

        'outputHandler' => null,
Severity: Critical
Found in src/Timer.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.

Assigning array<string></string> to property but \PerformanceTimer\Timer::$settings is array<string>|array<string>|array<string>|array{throwExceptions:true,outputHandler:null,profileNamespace:''}</string></string></string>
Open

            self::$settings['outputHandler'] = new ToLogFileHandler();
Severity: Minor
Found in src/Timer.php by phan

Call to method handle on non-class type null
Open

        $result = self::$settings['outputHandler']->handle(self::$results);
Severity: Critical
Found in src/Timer.php by phan

There are no issues that match your filters.

Category
Status