lib/Ajde/Cache.php

Summary

Maintainability
A
25 mins
Test Coverage

modifiedSince accesses the super-global variable $_SERVER.
Open

    public function modifiedSince()
    {
        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
            return $this->getLastModified() > strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
        }
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

ETagMatch accesses the super-global variable $_SERVER.
Open

    public function ETagMatch($serverETag = null)
    {
        if (empty($serverETag) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
            $serverETag = $_SERVER['HTTP_IF_NONE_MATCH'];
        }
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

modifiedSince accesses the super-global variable $_SERVER.
Open

    public function modifiedSince()
    {
        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
            return $this->getLastModified() > strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
        }
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

ETagMatch accesses the super-global variable $_SERVER.
Open

    public function ETagMatch($serverETag = null)
    {
        if (empty($serverETag) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
            $serverETag = $_SERVER['HTTP_IF_NONE_MATCH'];
        }
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Function saveResponse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function saveResponse()
    {
        $response = Ajde::app()->getResponse();
        $document = Ajde::app()->getDocument();

Severity: Minor
Found in lib/Ajde/Cache.php - About 25 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 method saveResponse uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $response->addHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $document->getMaxAge()));
            $response->addHeader('Cache-Control', $document->getCacheControl().', max-age='.$document->getMaxAge());
        }
Severity: Minor
Found in lib/Ajde/Cache.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 remember uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $result = $callback->__invoke();
            file_put_contents(LOCAL_ROOT.$cacheFilename, json_encode($result));

            return $result;
Severity: Minor
Found in lib/Ajde/Cache.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 saveResponse uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $response->addHeader('Last-Modified', gmdate('D, d M Y H:i:s', $this->getLastModified()).' GMT');
            $response->addHeader('Etag', $this->getHash());
            $response->addHeader('Content-Type', $document->getContentType());
            $response->setData($this->hasContents() ? $this->getContents() : false);
Severity: Minor
Found in lib/Ajde/Cache.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 property $_hashContext is not named in camelCase.
Open

class Ajde_Cache extends Ajde_Object_Singleton
{
    protected $_hashContext;
    protected $_hashFinal;
    protected $_lastModified = [];
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The property $_lastModified is not named in camelCase.
Open

class Ajde_Cache extends Ajde_Object_Singleton
{
    protected $_hashContext;
    protected $_hashFinal;
    protected $_lastModified = [];
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The class Ajde_Cache is not named in CamelCase.
Open

class Ajde_Cache extends Ajde_Object_Singleton
{
    protected $_hashContext;
    protected $_hashFinal;
    protected $_lastModified = [];
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

The property $_contents is not named in camelCase.
Open

class Ajde_Cache extends Ajde_Object_Singleton
{
    protected $_hashContext;
    protected $_hashFinal;
    protected $_lastModified = [];
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The property $_hashFinal is not named in camelCase.
Open

class Ajde_Cache extends Ajde_Object_Singleton
{
    protected $_hashContext;
    protected $_hashFinal;
    protected $_lastModified = [];
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The property $_enabled is not named in camelCase.
Open

class Ajde_Cache extends Ajde_Object_Singleton
{
    protected $_hashContext;
    protected $_hashFinal;
    protected $_lastModified = [];
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The method ETagMatch is not named in camelCase.
Open

    public function ETagMatch($serverETag = null)
    {
        if (empty($serverETag) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
            $serverETag = $_SERVER['HTTP_IF_NONE_MATCH'];
        }
Severity: Minor
Found in lib/Ajde/Cache.php by phpmd

CamelCaseMethodName

Since: 0.2

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

Example

class ClassName {
    public function get_name() {
    }
}

Source

There are no issues that match your filters.

Category
Status