Method appendServicePage
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function appendServicePage($html, $serviceID)
{
$serviceProvider = ServiceProvider::getInstance();
$services = $serviceProvider->getServices();
$service = $services[$serviceID]::getInstance();
Function handle
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function handle()
{
global $INPUT;
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Missing class import via use statement (line '151', column '25'). Open
$form = new \dokuwiki\Form\Form(['data-service' => $serviceID]);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '136', column '31'). Open
$configForm = new \dokuwiki\Form\Form();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\dokuwiki\plugin\issuelinks\classes\ServiceProvider' in method 'handle'. Open
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method appendServicePage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
global $INPUT;
$reconfigureURL = $INPUT->server->str('REQUEST_URI') . '&reconfigureService=' . $serviceID;
$reconfigureLink = "<a href=\"$reconfigureURL\">{$this->getLang('label: reconfigure service')}</a>";
$authorizedUserLabel = sprintf($this->getLang('label: authorized with user'), $service->getUserString());
- Read upRead up
- Exclude checks
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
Avoid using static access to class '\dokuwiki\plugin\issuelinks\classes\ServiceProvider' in method 'appendServiceTab'. Open
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\dokuwiki\plugin\issuelinks\classes\ServiceProvider' in method 'appendServicePage'. Open
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "authorize" 3 times. Open
if ($INPUT->has('authorize')) {
- 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.
Avoid unused parameters such as '$language'. Open
public function getMenuText($language)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Possibly zero references to use statement for classlike/namespace ServiceInterface
(\dokuwiki\plugin\issuelinks\services\ServiceInterface)
Open
use dokuwiki\plugin\issuelinks\services\ServiceInterface;
- Exclude checks
Class extends undeclared class \DokuWiki_Admin_Plugin
Open
class admin_plugin_issuelinks_repoadmin extends DokuWiki_Admin_Plugin
- Exclude checks
Call to method toHTML
from undeclared class \dokuwiki\Form\Form
Open
$html .= $configForm->toHTML();
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getLang
Open
$form->addFieldsetOpen($this->getLang("legend:group $serviceID"));
- Exclude checks
Call to method __construct
from undeclared class \dokuwiki\Form\Form
Open
$form = new \dokuwiki\Form\Form(['data-service' => $serviceID]);
- Exclude checks
Call to method addHTML
from undeclared class \dokuwiki\Form\Form
Open
$form->addHTML($authorizedUserLabel . ' ' . $reconfigureLink);
- Exclude checks
Call to method addTagClose
from undeclared class \dokuwiki\Form\Form
Open
$form->addTagClose('p');
- Exclude checks
Reference to undeclared constant \DOKU_PLUGIN
Open
return DOKU_PLUGIN . $plugin . '/images/issue-opened.svg';
- Exclude checks
Call to method addFieldsetOpen
from undeclared class \dokuwiki\Form\Form
Open
$configForm->addFieldsetOpen();
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getLang
Open
$configForm->addButton('', $this->getLang('btn:Submit'))->attr('type', 'submit');
- Exclude checks
Reference to undeclared constant \dokuwiki\plugin\issuelinks\services\ServiceInterface::DISPLAY_NAME
Open
$serviceName = $service::DISPLAY_NAME;
- Exclude checks
Call to method addFieldsetOpen
from undeclared class \dokuwiki\Form\Form
Open
$form->addFieldsetOpen($this->getLang('legend:user'));
- Exclude checks
Call to method addButton
from undeclared class \dokuwiki\Form\Form
Open
$configForm->addButton('', $this->getLang('btn:Submit'))->attr('type', 'submit');
- Exclude checks
Call to method addFieldsetOpen
from undeclared class \dokuwiki\Form\Form
Open
$form->addFieldsetOpen($this->getLang("legend:group $serviceID"));
- Exclude checks
Call to method addDropdown
from undeclared class \dokuwiki\Form\Form
Open
$form->addDropdown(
- Exclude checks
Call to method addClass
from undeclared class \dokuwiki\Form\Form
Open
$configForm->addClass('plugin__repoadmin_serviceConfig');
- Exclude checks
Call to method __construct
from undeclared class \dokuwiki\Form\Form
Open
$configForm = new \dokuwiki\Form\Form();
- Exclude checks
Call to method addFieldsetClose
from undeclared class \dokuwiki\Form\Form
Open
$configForm->addFieldsetClose();
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getLang
Open
$authorizedUserLabel = sprintf($this->getLang('label: authorized with user'), $service->getUserString());
- Exclude checks
Reference to undeclared constant \dokuwiki\plugin\issuelinks\services\ServiceInterface::DISPLAY_NAME
Open
$serviceName = $service::DISPLAY_NAME;
- Exclude checks
Call to method setHiddenField
from undeclared class \dokuwiki\Form\Form
Open
$configForm->setHiddenField('authorize', $serviceID);
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getLang
Open
$this->getLang("label $serviceID:choose organisation")
- Exclude checks
Call to method addFieldsetClose
from undeclared class \dokuwiki\Form\Form
Open
$form->addFieldsetClose();
- Exclude checks
Call to method addFieldsetClose
from undeclared class \dokuwiki\Form\Form
Open
$form->addFieldsetClose();
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getPluginName
Open
$plugin = $this->getPluginName();
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getLang
Open
return $this->getLang('menu:repo-admin');
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getLang
Open
$reconfigureLink = "<a href=\"$reconfigureURL\">{$this->getLang('label: reconfigure service')}</a>";
- Exclude checks
Call to method addTagOpen
from undeclared class \dokuwiki\Form\Form
Open
$form->addTagOpen('p');
- Exclude checks
Call to method toHTML
from undeclared class \dokuwiki\Form\Form
Open
$html .= $form->toHTML();
- Exclude checks
Call to undeclared method \admin_plugin_issuelinks_repoadmin::getLang
Open
$form->addFieldsetOpen($this->getLang('legend:user'));
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class admin_plugin_issuelinks_repoadmin extends DokuWiki_Admin_Plugin
- Exclude checks
The class admin_plugin_issuelinks_repoadmin is not named in CamelCase. Open
class admin_plugin_issuelinks_repoadmin extends DokuWiki_Admin_Plugin
{
private $orgs = [];
private $configNeeded = [];
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Class name "admin_plugin_issuelinks_repoadmin" is not in camel caps format Open
class admin_plugin_issuelinks_repoadmin extends DokuWiki_Admin_Plugin
- Exclude checks
The variable $INPUT is not named in camelCase. Open
protected function appendServicePage($html, $serviceID)
{
$serviceProvider = ServiceProvider::getInstance();
$services = $serviceProvider->getServices();
$service = $services[$serviceID]::getInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $INPUT is not named in camelCase. Open
protected function appendServicePage($html, $serviceID)
{
$serviceProvider = ServiceProvider::getInstance();
$services = $serviceProvider->getServices();
$service = $services[$serviceID]::getInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $INPUT is not named in camelCase. Open
public function handle()
{
global $INPUT;
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $INPUT is not named in camelCase. Open
public function handle()
{
global $INPUT;
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $INPUT is not named in camelCase. Open
public function handle()
{
global $INPUT;
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $INPUT is not named in camelCase. Open
public function handle()
{
global $INPUT;
$serviceProvider = ServiceProvider::getInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}