services/AbstractService.php
Method makeHTTPRequest
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
protected function makeHTTPRequest(\DokuHTTPClient $dokuHTTPClient, $url, $headers, array $data, $method)
The method getInstance has a boolean flag argument $forcereload, which is a certain sign of a Single Responsibility Principle violation. Open
Open
public static function getInstance($forcereload = false)
- Read upRead up
- Exclude checks
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
Open
throw new HTTPRequestException('request error', $dokuHTTPClient, $url, $method);
- Read upRead up
- Exclude checks
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
Open
$dokuHTTPClient->headers = array_merge($dokuHTTPClient->headers ?: [], $headers);
- Exclude checks
Call to method sendRequest
from undeclared class \DokuHTTPClient
Open
Open
$success = $dokuHTTPClient->sendRequest($url, $dataToBeSend, $method);
- Exclude checks
Instantiation of abstract class \dokuwiki\plugin\issuelinks\services\AbstractService
Open
Open
self::$instance[$class] = new $class();
- Exclude checks
Reference to instance property resp_body
from undeclared class \DokuHTTPClient
Open
Open
return json_decode($dokuHTTPClient->resp_body, true);
- Exclude checks
Reference to instance property status
from undeclared class \DokuHTTPClient
Open
Open
if (!$success || $dokuHTTPClient->status < 200 || $dokuHTTPClient->status > 206) {
- Exclude checks
Parameter $dokuHTTPClient
has undeclared type \DokuHTTPClient
Open
Open
protected function makeHTTPRequest(\DokuHTTPClient $dokuHTTPClient, $url, $headers, array $data, $method)
- Exclude checks
Reference to instance property status
from undeclared class \DokuHTTPClient
Open
Open
if ($dokuHTTPClient->status >= 500) {
- Exclude checks
Catching undeclared class \HTTPClientException
Open
Open
} catch (\HTTPClientException $e) {
- Exclude checks