mrcnpdlk/psr16cache-adapter

View on GitHub

Showing 7 of 7 total issues

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

    public function useCache(\Closure $closure, array $tHashKeys = null, $ttl = null)
    {
        if (!is_null($tHashKeys)) {
            $hashKey = $this->genHash($tHashKeys);
            if ($this->getCache()) {
Severity: Minor
Found in src/Adapter.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

The parameter $LogInterface is not named in camelCase.
Open

    public function setLoggerInstance(LoggerInterface $LogInterface = null)
    {
        $this->oLog = $LogInterface ?? new \Psr\Log\NullLogger();

        return $this;
Severity: Minor
Found in src/Adapter.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

Missing class import via use statement (line '114', column '44').
Open

        $this->oLog = $LogInterface ?? new \Psr\Log\NullLogger();
Severity: Minor
Found in src/Adapter.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 useCache uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $this->oLog->debug(sprintf('CACHE [%s]: not implemented', $hashKey));
                $answer = $closure();
            }
Severity: Minor
Found in src/Adapter.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 useCache uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $answer = $closure();
        }
Severity: Minor
Found in src/Adapter.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 useCache uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $answer = $closure();
                    $this->getCache()->set($hashKey, $answer, $ttl);
                    $this->oLog->debug(sprintf('CACHE [%s]: old, reset', $hashKey));
                }
Severity: Minor
Found in src/Adapter.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 variable $LogInterface is not named in camelCase.
Open

    public function setLoggerInstance(LoggerInterface $LogInterface = null)
    {
        $this->oLog = $LogInterface ?? new \Psr\Log\NullLogger();

        return $this;
Severity: Minor
Found in src/Adapter.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

Severity
Category
Status
Source
Language