steadlane/silverstripe-cloudflare

View on GitHub
src/Purge/Purge.php

Summary

Maintainability
D
1 day
Test Coverage

File Purge.php has 345 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace SteadLane\Cloudflare;

use SilverStripe\Core\Extensible;
Severity: Minor
Found in src/Purge/Purge.php - About 4 hrs to fix

Function fileSearchAux has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    private function fileSearchAux($dir, $pattern, &$files) {
        $handle = opendir($dir);
        if ($handle) {
            while (($file = readdir($handle)) !== false) {

Severity: Minor
Found in src/Purge/Purge.php - About 3 hrs 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

Purge has 27 functions (exceeds 20 allowed). Consider refactoring.
Open

class Purge
{
    use Injectable;
    use Extensible;

Severity: Minor
Found in src/Purge/Purge.php - About 3 hrs to fix

Method quick has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.php - About 1 hr to fix

Function isSuccessful has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function isSuccessful()
    {
        $response = $this->getResponse();

        if (!is_array($response)) {
Severity: Minor
Found in src/Purge/Purge.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 quick has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.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 too many return statements within this method.
Open

        return false;
Severity: Major
Found in src/Purge/Purge.php - About 30 mins to fix

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

    public function getUrlVariants($urls)
    {
        $output = array();

        foreach ($urls as $url) {
Severity: Minor
Found in src/Purge/Purge.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

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

    public function handleRequest(array $data = null, $isRecursing = null, $method = 'DELETE')
    {
        if (array_key_exists('files', $data) && !$isRecursing) {
            // get URL variants
            $data['files'] = $this->getUrlVariants($data['files']);
Severity: Minor
Found in src/Purge/Purge.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

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

    public function isBlacklisted($dir) {
        if (!is_array($blacklist = CloudFlare::config()->purge_dir_blacklist)) {
            return false;
        }

Severity: Minor
Found in src/Purge/Purge.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

TODO found
Open

        // @TODO: get rid of this stupidity, surely we don't need to use DOCUMENT_ROOT at all?
Severity: Minor
Found in src/Purge/Purge.php by fixme

The parameter $other_id is not named in camelCase.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.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 $other_id is not named in camelCase.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.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 $other_id is not named in camelCase.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.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 $other_id is not named in camelCase.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.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 $other_id is not named in camelCase.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.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 $other_id is not named in camelCase.
Open

    public function quick($what, $other_id = null)
    {
        // create a new instance of self so we don't interrupt anything
        $purger = self::create();
        $what = trim(strtolower($what));
Severity: Minor
Found in src/Purge/Purge.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