The method php_value() contains an eval expression. Open
if (@eval($jsValue. ';') === false) {
- Read upRead up
- Exclude checks
EvalExpression
Since: 0.2
An eval-expression is untestable, a security risk and bad practice. Therefore it should be avoided. Consider to replace the eval-expression with regular code.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
eval('$param = 23;');
}
}
}
Source https://phpmd.org/rules/design.html#evalexpression
The class Option has an overall complexity of 62 which is very high. The configured complexity threshold is 50. Open
class Option extends JqAttributes {
public $type;
public $phpType;
public $defaultValue = null;
public $propName;
- Exclude checks
File jq_control.php
has 290 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
//include_once('simple_html_dom.php');
require('qcubed.inc.php');
require(__INCLUDES__ . '/codegen/QCodeGen.class.php');
Function __construct
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($name, $origName, $signature, $description) {
parent::__construct($origName, $description);
$this->name = ucfirst($name);
$signature = str_replace("\n", '', $signature);
$this->signature = $signature;
- 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 __construct
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct($name, $origName, $signature, $description) {
parent::__construct($origName, $description);
$this->name = ucfirst($name);
$signature = str_replace("\n", '', $signature);
$this->signature = $signature;
Method php_type
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
static public function php_type($jsType) {
$jsType = strtolower($jsType);
$jsType = preg_replace('/\([^\)]*\)/', '', $jsType); // erase possible function args
if (strchr($jsType, ',')) return 'mixed';
if (strchr($jsType, ' or ')) return 'mixed';
Function __construct
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($strJqClass = null, $strJqSetupFunc = null, $strQcClass = null, $strQcBaseClass = 'QPanel')
{
$this->strJqClass = $strJqClass;
if ($strJqSetupFunc === null) {
- 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 __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function __construct($propName, $origName, $jsType, $defaultValue, $description, $phpType = null) {
Method __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function __construct($strQcClass, $name, $origName, $jsType, $description, $phpType = null) {
Avoid too many return
statements within this method. Open
case 'selector': return 'mixed';
Avoid too many return
statements within this method. Open
default: return 'mix';
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
case 'object[]': return 'object[]';
Avoid too many return
statements within this method. Open
case 'double': return 'flt';
Avoid too many return
statements within this method. Open
case 'double': return 'float';
Avoid too many return
statements within this method. Open
case 'boolean': return 'boolean';
Avoid too many return
statements within this method. Open
case 'object': return 'mixed';
Avoid too many return
statements within this method. Open
case 'number[]': return 'int[]';
Avoid too many return
statements within this method. Open
case 'int[]': return 'int[]';
Avoid too many return
statements within this method. Open
case 'QDateTime': return 'QType::DateTime';
Avoid too many return
statements within this method. Open
default: return "'".$phpType."'";
Avoid too many return
statements within this method. Open
case 'int': return 'integer';
Avoid too many return
statements within this method. Open
case 'integer': return 'int';
Avoid too many return
statements within this method. Open
case 'integer[]': return 'int[]';
Avoid too many return
statements within this method. Open
case 'double[]': return 'float[]';
Avoid too many return
statements within this method. Open
case 'string[]': return 'string[]';
Avoid too many return
statements within this method. Open
case 'QDateTime': return 'dtt';
Avoid too many return
statements within this method. Open
case 'string': return 'string';
Avoid too many return
statements within this method. Open
case 'date': return 'QDateTime';
Avoid too many return
statements within this method. Open
case 'integer': return 'integer';
Avoid too many return
statements within this method. Open
case 'options': return 'array';
Avoid too many return
statements within this method. Open
case 'array[]': return 'array[]';
Avoid too many return
statements within this method. Open
case 'float': return 'float';
Avoid too many return
statements within this method. Open
case 'double': return 'QType::Float';
Avoid too many return
statements within this method. Open
case 'number': return 'integer';
Avoid too many return
statements within this method. Open
case 'array': return 'arr';
Avoid too many return
statements within this method. Open
case 'boolean[]': return 'boolean[]';
Avoid too many return
statements within this method. Open
case 'array': return 'QType::ArrayType';
Avoid too many return
statements within this method. Open
return $jsValue;
Avoid too many return
statements within this method. Open
case 'float[]': return 'float[]';
Avoid too many return
statements within this method. Open
case 'date[]': return 'QDateTime[]';
Avoid too many return
statements within this method. Open
default: return 'QJsClosure';
Function php_value
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
static public function php_value($jsValue) {
//todo: add proper parsing
$jsValue = trim($jsValue);
if (!$jsValue)
return null;
- 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 php_type() has a Cyclomatic Complexity of 26. The configured cyclomatic complexity threshold is 10. Open
static public function php_type($jsType) {
$jsType = strtolower($jsType);
$jsType = preg_replace('/\([^\)]*\)/', '', $jsType); // erase possible function args
if (strchr($jsType, ',')) return 'mixed';
if (strchr($jsType, ' or ')) return 'mixed';
- 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 '23', column '15'). Open
$html = new \Html2Text\Html2Text($description);
- 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
Remove error control operator '@' on line 130. Open
static public function php_value($jsValue) {
//todo: add proper parsing
$jsValue = trim($jsValue);
if (!$jsValue)
return null;
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Missing class import via use statement (line '312', column '12'). Open
$r = new ReflectionClass($this->strQcBaseClass);
- 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 jq_indent has a boolean flag argument $blnComment, which is a certain sign of a Single Responsibility Principle violation. Open
function jq_indent ($strText, $intCount, $blnComment = 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
The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->strJqSetupFunc = $strJqSetupFunc;
}
- 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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->eventName = $jsType;
}
- 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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->strQcClass = $strQcClass;
}
- 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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->phpSignature .= '$'.$arg;
$this->requiredArgs[] = '$'.$arg;
}
- 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
TODO found Open
// TODO: better handle variable length argument list
- Exclude checks
Avoid excessively long variable names like $strOutDirControlsBase. Keep variable name length under 20. Open
public function GenerateControl($objJqDoc, $strOutDirControls, $strOutDirControlsBase) {
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = 1;
- 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
Avoid variables with short names like $r. Configured minimum length is 3. Open
$r = new ReflectionClass($this->strQcBaseClass);
- 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
The variable $unique_name is not named in camelCase. Open
protected function unique_name($name) {
$i = 1;
$unique_name = $name;
while ($this->has_name($unique_name)) {
$unique_name = $name.$i;
- 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 $unique_name is not named in camelCase. Open
protected function unique_name($name) {
$i = 1;
$unique_name = $name;
while ($this->has_name($unique_name)) {
$unique_name = $name.$i;
- 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 $unique_name is not named in camelCase. Open
protected function unique_name($name) {
$i = 1;
$unique_name = $name;
while ($this->has_name($unique_name)) {
$unique_name = $name.$i;
- 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 $unique_name is not named in camelCase. Open
protected function unique_name($name) {
$i = 1;
$unique_name = $name;
while ($this->has_name($unique_name)) {
$unique_name = $name.$i;
- 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 $unique_name is not named in camelCase. Open
protected function unique_name($name) {
$i = 1;
$unique_name = $name;
while ($this->has_name($unique_name)) {
$unique_name = $name.$i;
- 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 method reset_names is not named in camelCase. Open
protected function reset_names() {
$this->names = array();
}
- 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() {
}
}
Source
The method unique_name is not named in camelCase. Open
protected function unique_name($name) {
$i = 1;
$unique_name = $name;
while ($this->has_name($unique_name)) {
$unique_name = $name.$i;
- 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() {
}
}
Source
The method php_qtype is not named in camelCase. Open
static public function php_qtype($phpType) {
$phpType = str_replace('[]', '', $phpType);
switch ($phpType) {
case 'boolean': return 'QType::Boolean';
case 'string': return 'QType::String';
- 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() {
}
}
Source
The method GenerateControl is not named in camelCase. Open
public function GenerateControl($objJqDoc, $strOutDirControls, $strOutDirControlsBase) {
$mixArgumentArray = array('objJqDoc' => $objJqDoc);
$strResult = $this->EvaluatePHP(dirname(__FILE__) . '/jq_control.tpl.php', $mixArgumentArray);
$strOutFileName = $strOutDirControlsBase . '/'.$objJqDoc->strQcClass . 'Gen.class.php';
file_put_contents($strOutFileName, $strResult);
- 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() {
}
}
Source
The method has_name is not named in camelCase. Open
protected function has_name($name) {
return array_key_exists($name, $this->names);
}
- 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() {
}
}
Source
The method add_name is not named in camelCase. Open
protected function add_name($name) {
$this->names[$name] = $name;
}
- 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() {
}
}
Source
The method php_type is not named in camelCase. Open
static public function php_type($jsType) {
$jsType = strtolower($jsType);
$jsType = preg_replace('/\([^\)]*\)/', '', $jsType); // erase possible function args
if (strchr($jsType, ',')) return 'mixed';
if (strchr($jsType, ' or ')) return 'mixed';
- 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() {
}
}
Source
The method php_type_suffix is not named in camelCase. Open
static public function php_type_suffix($phpType) {
if (strpos($phpType, '[]') !== false)
return 'Array';
return '';
}
- 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() {
}
}
Source
The method php_type_prefix is not named in camelCase. Open
static public function php_type_prefix($phpType) {
$phpType = str_replace('[]', '', $phpType);
switch ($phpType) {
case 'boolean': return 'bln';
case 'string': return 'str';
- 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() {
}
}
Source
The method php_value is not named in camelCase. Open
static public function php_value($jsValue) {
//todo: add proper parsing
$jsValue = trim($jsValue);
if (!$jsValue)
return null;
- 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() {
}
}