steadlane/silverstripe-cloudflare

View on GitHub

Showing 49 of 49 total issues

The method log has a boolean flag argument $force, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function log($message, $force = false)
Severity: Minor
Found in src/Errors/Handlers.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

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

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

    public function prependServerName($input)
    {
        $serverName = CloudFlare::singleton()->getServerName();

        if (is_array($input)) {
Severity: Minor
Found in src/CloudFlare.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 unused parameters such as '$member'.
Open

    public function canUser($member)
Severity: Minor
Found in src/CloudFlare.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

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

        foreach ($this->providePermissions() as $permission => $context) {
Severity: Minor
Found in src/Admin/CloudFlareAdmin.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

The method getAuthHeaders() contains an exit expression.
Open

            exit;
Severity: Minor
Found in src/CloudFlare.php by phpmd

ExitExpression

Since: 0.2

An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

Example

class Foo {
    public function bar($param)  {
        if ($param === 42) {
            exit(23);
        }
    }
}

Source https://phpmd.org/rules/design.html#exitexpression

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

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

    public function getAuthHeaders()
    {
        if (getenv('TRAVIS')) {
            $auth = array(
                'email' => getenv('AUTH_EMAIL'),
Severity: Minor
Found in src/CloudFlare.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 '135', column '30').
Open

    public function fetchZoneID()
    {
        if (!$this->hasCFCredentials()) {
            return null;
        }
Severity: Minor
Found in src/CloudFlare.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 '160', column '15').
Open

    public function purge_single()
    {
        if (!Permission::check('CF_PURGE_SINGLE')) {
            Security::permissionFailure();
        }
Severity: Minor
Found in src/Admin/CloudFlareAdmin.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

The method onAfterPublish() has an NPath complexity of 1732. The configured NPath complexity threshold is 200.
Open

    public function onAfterPublish(&$original)
    {
        // if the page was just created, then there is no cache to purge and $original doesn't actually exist so bail out - resolves #3
        // we don't purge anything if we're operating on localhost
        if (CloudFlare::singleton()->hasCFCredentials() && $original && strlen($original->URLSegment) && Permission::check('CF_PURGE_PAGE')) {

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

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

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

The method HasAnyAccess is not named in camelCase.
Open

    public function HasAnyAccess()
    {
        foreach ($this->providePermissions() as $permission => $context) {
            if (!Permission::check($permission)) {
                return false;
Severity: Minor
Found in src/Admin/CloudFlareAdmin.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

The method ZoneID is not named in camelCase.
Open

    public function ZoneID()
    {
        return (CloudFlare::singleton()->fetchZoneID() ?: _t("CloudFlare.UnableToDetect", "UNABLE TO DETECT"));
    }
Severity: Minor
Found in src/Admin/CloudFlareAdmin.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

The method purge_javascript is not named in camelCase.
Open

    public function purge_javascript()
    {
        if (!Permission::check('CF_PURGE_JAVASCRIPT')) {
            Security::permissionFailure();
        }
Severity: Minor
Found in src/Admin/CloudFlareAdmin.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

Severity
Category
Status
Source
Language