bkdotcom/PHPDebugConsole

View on GitHub
src/Debug/ServiceProvider.php

Summary

Maintainability
A
0 mins
Test Coverage
B
88%

Method registerCoreServices has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Wontfix

    protected function registerCoreServices(Container $container) // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
    {
        $container['abstracter'] = static function (Container $container) {
            $debug = $container['debug'];
            return new \bdk\Debug\Abstraction\Abstracter($debug, $debug->getCfg('abstracter', Debug::CONFIG_INIT));
Severity: Major
Found in src/Debug/ServiceProvider.php - About 2 hrs to fix

    Method registerUtilities has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Wontfix

        protected function registerUtilities(Container $container) // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
        {
            $container['arrayUtil'] = static function () {
                return new \bdk\Debug\Utility\ArrayUtil();
            };
    Severity: Minor
    Found in src/Debug/ServiceProvider.php - About 1 hr to fix

      Define a constant instead of duplicating this literal "debug" 11 times.
      Open

                  $debug = $container['debug'];
      Severity: Critical
      Found in src/Debug/ServiceProvider.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 and throw a dedicated exception instead of using a generic one.
      Open

                      throw new RuntimeException('Wamp route requires \bdk\WampPublisher, which must be installed separately');
      Severity: Major
      Found in src/Debug/ServiceProvider.php by sonar-php

      If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

      Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

      Noncompliant Code Example

      throw new Exception();  // Noncompliant
      

      Compliant Solution

      throw new InvalidArgumentException();
      // or
      throw new UnexpectedValueException();
      

      See

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

                                  if (!empty($frame['context'])) {
      Severity: Critical
      Found in src/Debug/ServiceProvider.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 "errorHandler" 3 times.
      Open

                  'errorHandler',
      Severity: Critical
      Found in src/Debug/ServiceProvider.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 "wampPublisher" 3 times.
      Open

                      $wampPublisher = $container['wampPublisher'];
      Severity: Critical
      Found in src/Debug/ServiceProvider.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 "serverRequest" 3 times.
      Open

                  'serverRequest',
      Severity: Critical
      Found in src/Debug/ServiceProvider.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 and throw a dedicated exception instead of using a generic one.
      Open

                      throw new RuntimeException('PHPDebugConsole does not include WampPublisher.  Install separately');
      Severity: Major
      Found in src/Debug/ServiceProvider.php by sonar-php

      If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

      Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

      Noncompliant Code Example

      throw new Exception();  // Noncompliant
      

      Compliant Solution

      throw new InvalidArgumentException();
      // or
      throw new UnexpectedValueException();
      

      See

      There are no issues that match your filters.

      Category
      Status