Showing 289 of 289 total issues
Method addContainer
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function addContainer($html, $options, $numLines)
{
$customCSSClass = empty($options['class']) ? '' : ' ' . $options['class'];
if ($options['inline']) {
$theme = empty($options['inline_theme']) ? 'default' : $options['inline_theme'];
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class CodeColorer
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class CodeColorerOptions
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class CodeColorerAdmin
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class CodeColorerLoader
- Exclude checks
Function parseOptions
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function parseOptions($opts, $suffix = '')
{
$opts = str_replace(array("\\\"", "\\\'"), array ("\"", "\'"), $opts);
preg_match_all('#([a-z_-]*?)\s*=\s*(["\'])(.*?)\2#i', $opts, $matches, PREG_SET_ORDER);
$options = array();
- 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
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 36 and the first side effect is on line 33. Open
<?php
- Exclude checks
Avoid variables with short names like $to. Configured minimum length is 3. Open
list($from, $to) = array_pad(explode('-', $v, 2), 2, null);
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Method performHighlightCodeBlock
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private function performHighlightCodeBlock($text, $opts, $content, $suffix = '', $before = '', $after = '')
Missing class import via use statement (line '217', column '32'). Open
$this->geshi = new GeSHi();
- 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 '376', column '38'). Open
$this->optionsPage = new CodeColorerAdmin($this);
- 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
The method getBlockID has a boolean flag argument $comment, which is a certain sign of a Single Responsibility Principle violation. Open
private function getBlockID($content, $comment = false, $before = '<div>', $after = '</div>')
- 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
Missing class import via use statement (line '405', column '29'). Open
$instance = new CodeColorer();
- 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
Function getOptionsPage
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getOptionsPage()
{
if (!$this->optionsPage) {
if (!class_exists('CodeColorerAdmin')) {
$path = dirname(__FILE__);
- 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
The method getInstance uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$instance->geshiExternal = true;
}
- 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 'CodeColorer' in method 'callBeforeProtectComment'. Open
$codecolorer = &CodeColorer::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 performHighlightGeshi uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$table .= 'class="line-numbers"';
}
- 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
The method populateDefaultValues() has 128 lines of code. Current threshold is set to 100. Avoid really long methods. Open
protected static function populateDefaultValues($options)
{
if (!$options) {
$options = array();
}
- Exclude checks
Avoid using static access to class 'CodeColorerOptions' in method 'performHighlightGeshi'. Open
$table .= 'style="' . CodeColorerOptions::feedLineNumbersStyle() . '"';
- 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 show() has 125 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function show()
{
?>
<div class="wrap">
- Exclude checks