query accesses the super-global variable $GLOBALS. Open
function query($sql) {
//echo "<li>" . $sql . "</li>";
$db = $GLOBALS['xoopsDB'];
if (!($ret = $db->queryF($sql))) {
echo "<li style='font-weight: bold; color: red;'>" . $db->error() . "</li>";
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
apply_alter_tables accesses the super-global variable $GLOBALS. Open
function apply_alter_tables() {
$db = $GLOBALS['xoopsDB'];
$this->fields = array(
"config" => array(
"conf_title" => "varchar(255) NOT NULL default ''",
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
check_config_type accesses the super-global variable $GLOBALS. Open
function check_config_type() {
$db = $GLOBALS['xoopsDB'];
$sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
$result = $db->queryF( $sql );
while ($row = $db->fetchArray($result)) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Avoid unused local variables such as '$ret'. Open
if (!($ret = $db->queryF($sql))) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Reference to undeclared property \upgrade_2018->fields
Open
$this->fields = array(
- Exclude checks
Reference to undeclared property \upgrade_2018->fields
Open
foreach ($this->fields as $table => $data) {
- Exclude checks
Avoid assigning values to variables in if clauses and the like (line '30', column '9'). Open
function query($sql) {
//echo "<li>" . $sql . "</li>";
$db = $GLOBALS['xoopsDB'];
if (!($ret = $db->queryF($sql))) {
echo "<li style='font-weight: bold; color: red;'>" . $db->error() . "</li>";
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class upgrade_2018 {
- Exclude checks
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = $GLOBALS['xoopsDB'];
- 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 $db. Configured minimum length is 3. Open
$db = $GLOBALS['xoopsDB'];
- 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 $db. Configured minimum length is 3. Open
$db = $GLOBALS['xoopsDB'];
- 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 class upgrade_2018 is not named in CamelCase. Open
class upgrade_2018 {
var $usedFiles = array( );
function isApplied() {
- 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
Method name "upgrade_2018::check_config_type" is not in camel caps format Open
function check_config_type() {
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
foreach ($this->fields as $table => $data) {
- Exclude checks
Visibility must be declared on method "apply" Open
function apply() {
- Exclude checks
Method name "upgrade_2018::apply_alter_tables" is not in camel caps format Open
function apply_alter_tables() {
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
),
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
);
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
$sql = "ALTER TABLE " . $db->prefix($table) . " CHANGE `$field` `$field` $property";
- Exclude checks
Visibility must be declared on property "$usedFiles" Open
var $usedFiles = array( );
- Exclude checks
Visibility must be declared on method "isApplied" Open
function isApplied() {
- Exclude checks
Visibility must be declared on method "apply_alter_tables" Open
function apply_alter_tables() {
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
"conf_desc" => "varchar(255) NOT NULL default ''"
- Exclude checks
Visibility must be declared on method "check_config_type" Open
function check_config_type() {
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
foreach ($data as $field => $property) {
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
$this->query( $sql );
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
"conf_title" => "varchar(255) NOT NULL default ''",
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
"configcategory" => array( "confcat_name" => "varchar(255) NOT NULL default ''" ),
- Exclude checks
Visibility must be declared on method "query" Open
function query($sql) {
- Exclude checks
The var keyword must not be used to declare a property Open
var $usedFiles = array( );
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
"config" => array(
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
}
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
}
- Exclude checks
Tabs must be used to indent lines; spaces are not allowed Open
return true;
- Exclude checks
Line indented incorrectly; expected 3 tabs, found 11 Open
foreach ($data as $field => $property) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
$this->query( $sql );
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
$result = $db->queryF( $sql );
- Exclude checks
Line indented incorrectly; expected 2 tabs, found 10 Open
}
- Exclude checks
Space after opening parenthesis of function call prohibited Open
$this->query( $sql );
- Exclude checks
Space after opening parenthesis of function call prohibited Open
$result = $db->queryF( $sql );
- Exclude checks
Line indented incorrectly; expected 2 tabs, found 10 Open
foreach ($this->fields as $table => $data) {
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
if (strtolower( trim($row["Type"]) ) == "varchar(255)") {
- Exclude checks
Line indented incorrectly; expected 3 tabs, found 11 Open
}
- Exclude checks
Space after opening parenthesis of function call prohibited Open
if (strtolower( trim($row["Type"]) ) == "varchar(255)") {
- Exclude checks
A closing tag is not permitted at the end of a PHP file Open
?>
- Exclude checks
Class name "upgrade_2018" is not in camel caps format Open
class upgrade_2018 {
- Exclude checks
The method apply_alter_tables is not named in camelCase. Open
function apply_alter_tables() {
$db = $GLOBALS['xoopsDB'];
$this->fields = array(
"config" => array(
"conf_title" => "varchar(255) NOT NULL default ''",
- 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 check_config_type is not named in camelCase. Open
function check_config_type() {
$db = $GLOBALS['xoopsDB'];
$sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
$result = $db->queryF( $sql );
while ($row = $db->fetchArray($result)) {
- 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
Unexpected spaces found. Open
$this->query( $sql );
- Exclude checks
Unexpected spaces found. Open
),
- Exclude checks
Unexpected spaces found. Open
"configcategory" => array( "confcat_name" => "varchar(255) NOT NULL default ''" ),
- Exclude checks
Unexpected spaces found. Open
$sql = "ALTER TABLE " . $db->prefix($table) . " CHANGE `$field` `$field` $property";
- Exclude checks
Unexpected spaces found. Open
}
- Exclude checks
Unexpected spaces found. Open
"config" => array(
- Exclude checks
Unexpected spaces found. Open
"conf_title" => "varchar(255) NOT NULL default ''",
- Exclude checks
Unexpected spaces found. Open
foreach ($this->fields as $table => $data) {
- Exclude checks
Unexpected spaces found. Open
foreach ($data as $field => $property) {
- Exclude checks
Unexpected spaces found. Open
return true;
- Exclude checks
Unexpected spaces found. Open
}
- Exclude checks
Unexpected spaces found. Open
);
- Exclude checks
Unexpected spaces found. Open
"conf_desc" => "varchar(255) NOT NULL default ''"
- Exclude checks