Avoid using undefined variables such as '$valid_question_types' which will lead to PHP notices. Open
$valid_question_types[] = $key;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$valid_question_types' which will lead to PHP notices. Open
if (in_array($parameter, $valid_question_types)) {
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
The method check_question_type uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return false;
}
- 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 unused local variables such as '$value'. Open
foreach ($question_list as $key => $value) {
- 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
Consider putting global function "check_question_type" in a static class Open
function check_question_type($parameter)
- Exclude checks
Variable "question_list_options" is not in valid camel caps format Open
$question_list_options,
- Exclude checks
Variable "exercise_id" is not in valid camel caps format Open
$exercise_id = (int) ($values['exercise']);
- Exclude checks
Variable "row_feedback_type" is not in valid camel caps format Open
$row_feedback_type = Database::fetch_row($rs_feedback_type);
- Exclude checks
Variable "rs_feedback_type" is not in valid camel caps format Open
$row_feedback_type = Database::fetch_row($rs_feedback_type);
- Exclude checks
Variable "row_feedback_type" is not in valid camel caps format Open
$feedback_type = $row_feedback_type[0];
- Exclude checks
Variable "feedback_type" is not in valid camel caps format Open
if ((HOT_SPOT_DELINEATION == $answer_type && 1 != $feedback_type) ||
- Exclude checks
Variable "answer_type" is not in valid camel caps format Open
(1 == $feedback_type && (HOT_SPOT_DELINEATION != $answer_type && UNIQUE_ANSWER != $answer_type))) {
- Exclude checks
Variable "question_list" is not in valid camel caps format Open
foreach ($question_list as $key => $value) {
- Exclude checks
Variable "rs_feedback_type" is not in valid camel caps format Open
$rs_feedback_type = Database::query($sql);
- Exclude checks
Variable "tbl_exercises" is not in valid camel caps format Open
$sql = "SELECT feedback_type FROM $tbl_exercises
- Exclude checks
Variable "feedback_type" is not in valid camel caps format Open
(1 == $feedback_type && (HOT_SPOT_DELINEATION != $answer_type && UNIQUE_ANSWER != $answer_type))) {
- Exclude checks
Variable "answer_type" is not in valid camel caps format Open
(1 == $feedback_type && (HOT_SPOT_DELINEATION != $answer_type && UNIQUE_ANSWER != $answer_type))) {
- Exclude checks
Variable "question_list" is not in valid camel caps format Open
$question_list = Question::getQuestionTypeList();
- Exclude checks
Variable "question_list_options" is not in valid camel caps format Open
$question_list_options = [];
- Exclude checks
Variable "question_list_options" is not in valid camel caps format Open
$question_list_options[$key] = addslashes(get_lang($value[1]));
- Exclude checks
Variable "session_id" is not in valid camel caps format Open
$session_id = api_get_session_id();
- Exclude checks
Variable "feedback_type" is not in valid camel caps format Open
$feedback_type = $row_feedback_type[0];
- Exclude checks
Missing function doc comment Open
function check_question_type($parameter)
- Exclude checks
Variable "answer_type" is not in valid camel caps format Open
$answer_type = $values['question_type_hidden'];
- Exclude checks
Variable "exercise_id" is not in valid camel caps format Open
WHERE iid = '$exercise_id'";
- Exclude checks
Variable "question_list" is not in valid camel caps format Open
foreach ($question_list as $key => $value) {
- Exclude checks
Variable "course_id" is not in valid camel caps format Open
$course_id = api_get_course_int_id();
- Exclude checks
Variable "this_section" is not in valid camel caps format Open
$this_section = SECTION_COURSES;
- Exclude checks
Variable "answer_type" is not in valid camel caps format Open
if ((HOT_SPOT_DELINEATION == $answer_type && 1 != $feedback_type) ||
- Exclude checks
Variable "answer_type" is not in valid camel caps format Open
header('Location: admin.php?exerciseId='.$values['exercise'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
- Exclude checks
Variable "valid_question_types" is not in valid camel caps format Open
$valid_question_types[] = $key;
- Exclude checks
Variable "question_list" is not in valid camel caps format Open
$question_list = Question::getQuestionTypeList();
- Exclude checks
Variable "tbl_exercises" is not in valid camel caps format Open
$tbl_exercises = Database::get_course_table(TABLE_QUIZ_TEST);
- Exclude checks
Variable "valid_question_types" is not in valid camel caps format Open
if (in_array($parameter, $valid_question_types)) {
- Exclude checks
The variable $question_list is not named in camelCase. Open
function check_question_type($parameter)
{
$question_list = Question::getQuestionTypeList();
foreach ($question_list as $key => $value) {
$valid_question_types[] = $key;
- 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 $valid_question_types is not named in camelCase. Open
function check_question_type($parameter)
{
$question_list = Question::getQuestionTypeList();
foreach ($question_list as $key => $value) {
$valid_question_types[] = $key;
- 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 $question_list is not named in camelCase. Open
function check_question_type($parameter)
{
$question_list = Question::getQuestionTypeList();
foreach ($question_list as $key => $value) {
$valid_question_types[] = $key;
- 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 $valid_question_types is not named in camelCase. Open
function check_question_type($parameter)
{
$question_list = Question::getQuestionTypeList();
foreach ($question_list as $key => $value) {
$valid_question_types[] = $key;
- 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();
}
}