Function DisplayHtml
has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring. Open
public static function DisplayHtml($strText, $strCssClass) {
$strText = trim(str_replace("\r", '', $strText));
$strToReturn = '';
$objStateStack = new QStack();
- 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
Method DisplayHtml
has 184 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function DisplayHtml($strText, $strCssClass) {
$strText = trim(str_replace("\r", '', $strText));
$strToReturn = '';
$objStateStack = new QStack();
The class QWriteBox has an overall complexity of 61 which is very high. The configured complexity threshold is 50. Open
class QWriteBox extends QTextBox {
protected $strTextMode = QTextMode::MultiLine;
protected $strCrossScripting = QCrossScripting::Allow;
protected $strCodeCssClass;
- Exclude checks
Consider simplifying this complex logical expression. Open
if ((mb_strlen($strTag, QApplication::$EncodingType) >= 8) && ((mb_substr($strTag, 0, 7, QApplication::$EncodingType) == 'http://') || (substr($strTag, 0, 8) == 'https://')) &&
(mb_strpos($strTag, '"', 0, QApplication::$EncodingType) === false) &&
(mb_strpos($strTag, ' ', 0, QApplication::$EncodingType) === false) &&
(mb_strpos($strTag, ' ', 0, QApplication::$EncodingType) === false)) {
$strToReturn .= sprintf('<<a href="%s">%s</a>>',
The method DisplayHtml() has an NPath complexity of 270. The configured NPath complexity threshold is 200. Open
public static function DisplayHtml($strText, $strCssClass) {
$strText = trim(str_replace("\r", '', $strText));
$strToReturn = '';
$objStateStack = new QStack();
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method DisplayHtml() has 206 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function DisplayHtml($strText, $strCssClass) {
$strText = trim(str_replace("\r", '', $strText));
$strToReturn = '';
$objStateStack = new QStack();
- Exclude checks
The method DisplayHtml() has a Cyclomatic Complexity of 52. The configured cyclomatic complexity threshold is 10. Open
public static function DisplayHtml($strText, $strCssClass) {
$strText = trim(str_replace("\r", '', $strText));
$strToReturn = '';
$objStateStack = new QStack();
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Missing class import via use statement (line '68', column '25'). Open
$objStateStack = new QStack();
- 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 'QType' in method '__set'. Open
return ($this->strCodeCssClass = QType::Cast($mixValue, QType::String));
- 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 'QApplication' in method '__construct'. Open
$this->strInstructions = QApplication::Translate('Tags <b> <u> <i> <br> <code> and <http://...> are allowed. Use ** at the beginning of any line for a bulleted list.');
- 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 'QWriteBox' in method '__get'. Open
return QWriteBox::DisplayHtml($this->strText, $this->strCodeCssClass);
- 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
Constant StateStar should be defined in uppercase Open
const StateStar = 4;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant StateCode should be defined in uppercase Open
const StateCode = 7;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant StateTag should be defined in uppercase Open
const StateTag = 3;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant StateNewLine should be defined in uppercase Open
const StateNewLine = 2;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant StateBulletedListItem should be defined in uppercase Open
const StateBulletedListItem = 6;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant StateBulletedList should be defined in uppercase Open
const StateBulletedList = 5;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant StateText should be defined in uppercase Open
const StateText = 1;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
The method DisplayHtml is not named in camelCase. Open
public static function DisplayHtml($strText, $strCssClass) {
$strText = trim(str_replace("\r", '', $strText));
$strToReturn = '';
$objStateStack = new QStack();
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}