bkdotcom/PHPDebugConsole

View on GitHub
src/Debug/Framework/Yii2/LogTarget.php

Summary

Maintainability
A
0 mins
Test Coverage

Reduce the number of returns of this function 4, down to the maximum allowed 3.
Open

    private function messageMeta($message)

Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

Noncompliant Code Example

With the default threshold of 3:

function myFunction(){ // Noncompliant as there are 4 return statements
  if (condition1) {
    return true;
  } else {
    if (condition2) {
      return false;
    } else {
      return true;
    }
  }
  return false;
}

Remove this unused private "messageMetaConnection" method.
Open

    private function messageMetaConnection($message)

private methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

Noncompliant Code Example

public class Foo
{
  private function Foo() {}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
    ...
  }

  private function unusedPrivateFunction() {  // Noncompliant
  }
}

Compliant Solution

public class Foo
{
  private function Foo(){}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
  }
}

See

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

            $duration = $message['timestamp'] - $messageBegin['timestamp'];

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.

Remove this unused private "messageMetaModule" method.
Open

    private function messageMetaModule($message)

private methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

Noncompliant Code Example

public class Foo
{
  private function Foo() {}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
    ...
  }

  private function unusedPrivateFunction() {  // Noncompliant
  }
}

Compliant Solution

public class Foo
{
  private function Foo(){}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
  }
}

See

Define a constant instead of duplicating this literal "category" 12 times.
Open

            \ltrim($message['category'] . ':', ':'),

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.

Remove this unused private "messageMetaApplication" method.
Open

    private function messageMetaApplication($message)

private methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

Noncompliant Code Example

public class Foo
{
  private function Foo() {}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
    ...
  }

  private function unusedPrivateFunction() {  // Noncompliant
  }
}

Compliant Solution

public class Foo
{
  private function Foo(){}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
  }
}

See

Rename "$debug" which has the same name as the field declared at line 30.
Open

        $debug = $message['channel'];

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Define a constant instead of duplicating this literal "channel" 9 times.
Open

        $debug = $message['channel'];

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 "channelIcon" 4 times.
Open

            'channelIcon' => $icon,

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 "level" 7 times.
Open

        if ($message['level'] === Logger::LEVEL_PROFILE_BEGIN) {

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.

Remove this unused private "messageMetaCaching" method.
Open

    private function messageMetaCaching($message)

private methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

Noncompliant Code Example

public class Foo
{
  private function Foo() {}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
    ...
  }

  private function unusedPrivateFunction() {  // Noncompliant
  }
}

Compliant Solution

public class Foo
{
  private function Foo(){}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
  }
}

See

Remove this unused private "messageMetaView" method.
Open

    private function messageMetaView($message)

private methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

Noncompliant Code Example

public class Foo
{
  private function Foo() {}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
    ...
  }

  private function unusedPrivateFunction() {  // Noncompliant
  }
}

Compliant Solution

public class Foo
{
  private function Foo(){}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.

  public static function doSomething()
  {
    $foo = new Foo();
  }
}

See

Define a constant instead of duplicating this literal "trace" 5 times.
Open

        Logger::LEVEL_TRACE => 'trace',

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