src/Storage/Filesystem.php

Summary

Maintainability
A
0 mins
Test Coverage

Function rmDir has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Invalid

    protected function rmDir(string $dir, bool $staleOnly = FALSE)
    {
        foreach (glob($dir . '{,.}[!.,!..]*', GLOB_MARK|GLOB_BRACE) as $file) {
            if (is_dir($file)) {
                $this->rmDir($file, $staleOnly);
Severity: Minor
Found in src/Storage/Filesystem.php - About 1 hr 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 getLock has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Invalid

    protected function getLock(string $path)
    {
        $lock = $path . '.lock';
        $count = 0;
        if ($fp = fopen($lock, 'c')) {
Severity: Minor
Found in src/Storage/Filesystem.php - About 1 hr 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

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

    public function __construct(
        string $rootPath,
        int $hashLevel = 2
    ) {
        if (!file_exists($rootPath) && !@mkdir($rootPath, 0777, TRUE)) {
Severity: Minor
Found in src/Storage/Filesystem.php by phpmd

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

Missing class import via use statement (line '47', column '23').
Open

            throw new \RuntimeException("Failed to create $rootPath");
Severity: Minor
Found in src/Storage/Filesystem.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

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

    public function delete(string $key): bool
    {
        $path = $this->getPath($key);
        if (file_exists($path) && $fp = $this->getLock($path)) {
            $res = unlink($path);
Severity: Minor
Found in src/Storage/Filesystem.php by phpmd

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

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

    public function set(string $key, string $value, int $ttl): bool
    {
        $path = $this->getPath($key);

        // write to a temp file first
Severity: Minor
Found in src/Storage/Filesystem.php by phpmd

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

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

    protected function getLock(string $path)
    {
        $lock = $path . '.lock';
        $count = 0;
        if ($fp = fopen($lock, 'c')) {
Severity: Minor
Found in src/Storage/Filesystem.php by phpmd

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

There are no issues that match your filters.

Category
Status