The method validate_courses_data uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// 2.2 Check whether course code has been occupied.
$courseInfo = api_get_course_info($course['Code']);
if (!empty($courseInfo)) {
$course['error'] = get_lang('This code exists');
- 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 validate_courses_data uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$course['error'] = get_lang('No course category was provided');
$errors[] = $course;
}
- 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
Variable "defined_auth_sources" is not in valid camel caps format Open
$defined_auth_sources[] = PLATFORM_AUTH_SOURCE;
- Exclude checks
Variable "error_course" is not in valid camel caps format Open
$error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';
- Exclude checks
Consider putting global function "parse_csv_courses_data" in a static class Open
function parse_csv_courses_data($file)
- Exclude checks
Variable "defined_auth_sources" is not in valid camel caps format Open
$defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));
- Exclude checks
Variable "ext_import_file" is not in valid camel caps format Open
$ext_import_file = substr($_FILES['import_file']['name'], strrpos($_FILES['import_file']['name'], '.') + 1);
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
$error_message = '<ul>';
- Exclude checks
Variable "tool_name" is not in valid camel caps format Open
$tool_name = get_lang('Import courses list').' CSV';
- Exclude checks
Variable "error_course" is not in valid camel caps format Open
$error_message .= get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')';
- Exclude checks
Variable "mandatory_fields" is not in valid camel caps format Open
foreach ($mandatory_fields as $field) {
- Exclude checks
Variable "allowed_file_mimetype" is not in valid camel caps format Open
if (!in_array($ext_import_file, $allowed_file_mimetype)) {
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
$error_message .= '</ul>';
- Exclude checks
Consider putting global function "getTeacherListInArray" in a static class Open
function getTeacherListInArray($teachers)
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
$error_message = get_lang('The file upload has failed.');
- Exclude checks
Consider putting global function "validate_courses_data" in a static class Open
function validate_courses_data($courses)
- Exclude checks
Variable "tool_name" is not in valid camel caps format Open
Display::display_header($tool_name);
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
echo Display::return_message($error_message, 'error', false);
- Exclude checks
Variable "mandatory_fields" is not in valid camel caps format Open
$mandatory_fields = ['Code', 'Title', 'CourseCategory'];
- Exclude checks
Variable "error_course" is not in valid camel caps format Open
foreach ($errors as $index => $error_course) {
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
$error_message .= get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')';
- Exclude checks
Variable "tool_name" is not in valid camel caps format Open
$form->addHeader($tool_name);
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
$error_message .= '</li>';
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
echo Display::return_message($error_message, 'error', false);
- Exclude checks
Variable "defined_auth_sources" is not in valid camel caps format Open
$defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));
- Exclude checks
Variable "error_message" is not in valid camel caps format Open
$error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';
- Exclude checks
Variable "error_course" is not in valid camel caps format Open
$error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';
- Exclude checks
Variable "course_language" is not in valid camel caps format Open
$course_language = $course['Language'];
- Exclude checks
Variable "course_language" is not in valid camel caps format Open
$params['course_language'] = $course_language;
- Exclude checks
Variable "allowed_file_mimetype" is not in valid camel caps format Open
$allowed_file_mimetype = ['csv'];
- Exclude checks
Variable "error_course" is not in valid camel caps format Open
$error_message .= get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')';
- Exclude checks
Consider putting global function "save_courses_data" in a static class Open
function save_courses_data($courses)
- Exclude checks
Variable "this_section" is not in valid camel caps format Open
$this_section = SECTION_PLATFORM_ADMIN;
- Exclude checks
Variable "ext_import_file" is not in valid camel caps format Open
if (!in_array($ext_import_file, $allowed_file_mimetype)) {
- Exclude checks
The variable $course_language is not named in camelCase. Open
function save_courses_data($courses)
{
$msg = '';
foreach ($courses as $course) {
$course_language = $course['Language'];
- 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 $mandatory_fields is not named in camelCase. Open
function validate_courses_data($courses)
{
$errors = [];
$coursecodes = [];
foreach ($courses as $index => $course) {
- 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 $course_language is not named in camelCase. Open
function save_courses_data($courses)
{
$msg = '';
foreach ($courses as $course) {
$course_language = $course['Language'];
- 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 $mandatory_fields is not named in camelCase. Open
function validate_courses_data($courses)
{
$errors = [];
$coursecodes = [];
foreach ($courses as $index => $course) {
- 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();
}
}