TikiWiki/tiki-manager

View on GitHub
src/Libs/Audit/Checksum.php

Summary

Maintainability
A
2 hrs
Test Coverage

The class Checksum has 11 public methods. Consider refactoring Checksum to keep number of public methods under 10.
Open

class Checksum
{
    const SQL_SELECT_FILE_MAP = <<<SQL
        SELECT
            path, hash
Severity: Minor
Found in src/Libs/Audit/Checksum.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Method validate has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function validate($version_id, $current_checksums = [])
    {

        $newFiles = [];
        $modifiedFiles = [];
Severity: Minor
Found in src/Libs/Audit/Checksum.php - About 1 hr to fix

    Function validate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function validate($version_id, $current_checksums = [])
        {
    
            $newFiles = [];
            $modifiedFiles = [];
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php - About 55 mins to fix

    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

    Function checksumFolder has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function checksumFolder($folder, $callback = null)
        {
            $result = [];
    
            if (!is_callable($callback)) {
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php - About 45 mins to fix

    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

    Avoid using undefined variables such as '$hash' which will lead to PHP notices.
    Open

                $map[$path] = $hash;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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 '$path' which will lead to PHP notices.
    Open

                $map[$path] = $hash;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    Missing class import via use statement (line '94', column '28').
    Open

            $objiterator = new \RecursiveIteratorIterator(
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    Missing class import via use statement (line '93', column '28').
    Open

            $diriterator = new \RecursiveDirectoryIterator($folder);
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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 validate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    if ($known[$filename] != $hash) {
                        $modifiedFiles[$filename] = $hash;
                    } else {
                        $pristineFiles[$filename] = $hash;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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 uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        $pristineFiles[$filename] = $hash;
                    }
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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 '$path'.
    Open

                $map[$path] = $hash;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    Avoid unused local variables such as '$hash'.
    Open

                $map[$path] = $hash;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    When fetching an array index from a value of type array<string>|array<string>,</string></string> found an array index of type 1, but expected the index to be of type string
    Open

                $next = $_GET[1];
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phan

    The parameter $version_id is not named in camelCase.
    Open

        public static function replaceFiles($version_id, $hashFiles)
        {
            query('BEGIN TRANSACTION');
            foreach ($hashFiles as $hashFile) {
                list($hash, $filename) = $hashFile;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function validate($version_id, $current_checksums = [])
        {
    
            $newFiles = [];
            $modifiedFiles = [];
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function addFiles($version_id, $hashFiles = [])
        {
            query('BEGIN TRANSACTION');
            foreach ($hashFiles as $hashFile) {
                list($hash, $filename) = $hashFile;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function saveChecksums($version_id, $entries)
        {
            query('BEGIN TRANSACTION');
    
            foreach ($entries as $parts) {
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function hasChecksums($version_id)
        {
            $args = [':id' => $version_id];
            $result = query(self::SQL_SELECT_FILE_COUNT_BY_VERSION, $args);
            return ($result->fetchColumn() > 0);
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function getChecksums($version_id)
        {
            $map = [];
            $result = query(self::SQL_SELECT_FILE_MAP, [':v' => $version_id]);
    
    
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function replaceFile($version_id, $hash, $filename)
        {
            self::removeFile($version_id, $filename);
            return self::addFile($version_id, $hash, $filename);
        }
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function removeFile($version_id, $filename)
        {
            $args = [':v' => $version_id, ':p' => $filename];
            return query(self::SQL_DELETE_FILE, $args);
        }
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $version_id is not named in camelCase.
    Open

        public static function addFile($version_id, $hash, $filename)
        {
            $args = [
                ':version' => $version_id,
                ':path' => $filename,
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The parameter $current_checksums is not named in camelCase.
    Open

        public static function validate($version_id, $current_checksums = [])
        {
    
            $newFiles = [];
            $modifiedFiles = [];
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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

    The variable $current_checksums is not named in camelCase.
    Open

        public static function validate($version_id, $current_checksums = [])
        {
    
            $newFiles = [];
            $modifiedFiles = [];
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function saveChecksums($version_id, $entries)
        {
            query('BEGIN TRANSACTION');
    
            foreach ($entries as $parts) {
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function replaceFile($version_id, $hash, $filename)
        {
            self::removeFile($version_id, $filename);
            return self::addFile($version_id, $hash, $filename);
        }
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function getChecksums($version_id)
        {
            $map = [];
            $result = query(self::SQL_SELECT_FILE_MAP, [':v' => $version_id]);
    
    
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function replaceFiles($version_id, $hashFiles)
        {
            query('BEGIN TRANSACTION');
            foreach ($hashFiles as $hashFile) {
                list($hash, $filename) = $hashFile;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function removeFile($version_id, $filename)
        {
            $args = [':v' => $version_id, ':p' => $filename];
            return query(self::SQL_DELETE_FILE, $args);
        }
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function addFiles($version_id, $hashFiles = [])
        {
            query('BEGIN TRANSACTION');
            foreach ($hashFiles as $hashFile) {
                list($hash, $filename) = $hashFile;
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function validate($version_id, $current_checksums = [])
        {
    
            $newFiles = [];
            $modifiedFiles = [];
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function replaceFile($version_id, $hash, $filename)
        {
            self::removeFile($version_id, $filename);
            return self::addFile($version_id, $hash, $filename);
        }
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function hasChecksums($version_id)
        {
            $args = [':id' => $version_id];
            $result = query(self::SQL_SELECT_FILE_COUNT_BY_VERSION, $args);
            return ($result->fetchColumn() > 0);
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

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

        public static function addFile($version_id, $hash, $filename)
        {
            $args = [
                ':version' => $version_id,
                ':path' => $filename,
    Severity: Minor
    Found in src/Libs/Audit/Checksum.php by phpmd

    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