chamilo/chamilo-lms

View on GitHub
public/main/inc/lib/fileManage.lib.php

Summary

Maintainability
A
0 mins
Test Coverage

Remove error control operator '@' on line 38.
Open

function removeDir($dir)
{
    if (!@$opendir = opendir($dir)) {
        return false;
    }

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

Remove error control operator '@' on line 25.
Open

function removeDir($dir)
{
    if (!@$opendir = opendir($dir)) {
        return false;
    }

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

Remove error control operator '@' on line 18.
Open

function removeDir($dir)
{
    if (!@$opendir = opendir($dir)) {
        return false;
    }

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

Avoid assigning values to variables in if clauses and the like (line '18', column '11').
Open

function removeDir($dir)
{
    if (!@$opendir = opendir($dir)) {
        return false;
    }

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

The method getAllPhpFiles uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            foreach ($extensionsArray as $extension) {
                if (substr($item, -strlen($extension)) == $extension) {
                    $files[] = $base_path . $item;
                    break;

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 parameter $base_path is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

Consider putting global function "getAllPhpFiles" in a static class
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array

Consider putting global function "removeDir" in a static class
Open

function removeDir($dir)

Variable "base_path" is not in valid camel caps format
Open

        if (in_array($base_path . $item . '/', $special_dirs)) {

Variable "base_path" is not in valid camel caps format
Open

            $files = array_merge($files, getAllPhpFiles($base_path . $item . '/', $includeStatic));

Variable "base_path" is not in valid camel caps format
Open

                    $files[] = $base_path . $item;

Variable "base_path" is not in valid camel caps format
Open

    $list = scandir($base_path);

Variable "special_dirs" is not in valid camel caps format
Open

        if (in_array($base_path . $item . '/', $special_dirs)) {

Variable "base_path" is not in valid camel caps format
Open

        if (is_dir($base_path . $item)) {

Consider putting global function "copyDirTo" in a static class
Open

function copyDirTo($source, $destination, $move = true)

Variable "base_path" is not in valid camel caps format
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array

Variable "special_dirs" is not in valid camel caps format
Open

        $special_dirs = []; // Modify this array as needed

The variable $base_path is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

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 $base_path is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

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 $base_path is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

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 $special_dirs is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

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 $special_dirs is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

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 $base_path is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

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 $base_path is not named in camelCase.
Open

function getAllPhpFiles(string $base_path, bool $includeStatic = false): array
{
    $list = scandir($base_path);
    $files = [];
    $extensionsArray = ['.php', '.tpl', '.html.twig'];

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

There are no issues that match your filters.

Category
Status