cosmocode/dokuwiki-plugin-issuelinks

View on GitHub
services/AbstractService.php

Summary

Maintainability
A
35 mins
Test Coverage

Method makeHTTPRequest has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    protected function makeHTTPRequest(\DokuHTTPClient $dokuHTTPClient, $url, $headers, array $data, $method)
Severity: Minor
Found in services/AbstractService.php - About 35 mins to fix

    The method getInstance has a boolean flag argument $forcereload, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public static function getInstance($forcereload = false)
    Severity: Minor
    Found in services/AbstractService.php by phpmd

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

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

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

                throw new HTTPRequestException('request error', $dokuHTTPClient, $url, $method);
    Severity: Critical
    Found in services/AbstractService.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.

    Reference to instance property headers from undeclared class \DokuHTTPClient
    Open

            $dokuHTTPClient->headers = array_merge($dokuHTTPClient->headers ?: [], $headers);
    Severity: Minor
    Found in services/AbstractService.php by phan

    Call to method sendRequest from undeclared class \DokuHTTPClient
    Open

                $success = $dokuHTTPClient->sendRequest($url, $dataToBeSend, $method);
    Severity: Critical
    Found in services/AbstractService.php by phan

    Instantiation of abstract class \dokuwiki\plugin\issuelinks\services\AbstractService
    Open

                self::$instance[$class] = new $class();
    Severity: Minor
    Found in services/AbstractService.php by phan

    Reference to instance property resp_body from undeclared class \DokuHTTPClient
    Open

            return json_decode($dokuHTTPClient->resp_body, true);
    Severity: Minor
    Found in services/AbstractService.php by phan

    Reference to instance property status from undeclared class \DokuHTTPClient
    Open

            if (!$success || $dokuHTTPClient->status < 200 || $dokuHTTPClient->status > 206) {
    Severity: Minor
    Found in services/AbstractService.php by phan

    Parameter $dokuHTTPClient has undeclared type \DokuHTTPClient
    Open

        protected function makeHTTPRequest(\DokuHTTPClient $dokuHTTPClient, $url, $headers, array $data, $method)
    Severity: Minor
    Found in services/AbstractService.php by phan

    Reference to instance property status from undeclared class \DokuHTTPClient
    Open

                if ($dokuHTTPClient->status >= 500) {
    Severity: Minor
    Found in services/AbstractService.php by phan

    Catching undeclared class \HTTPClientException
    Open

            } catch (\HTTPClientException $e) {
    Severity: Critical
    Found in services/AbstractService.php by phan

    There are no issues that match your filters.

    Category
    Status