steadlane/silverstripe-cloudflare

View on GitHub
src/CloudFlare.php

Summary

Maintainability
C
7 hrs
Test Coverage

File CloudFlare.php has 255 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace SteadLane\Cloudflare;

use Psr\Log\LoggerInterface;
Severity: Minor
Found in src/CloudFlare.php - About 2 hrs to fix

Method fetchZoneID has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function fetchZoneID()
    {
        if (!$this->hasCFCredentials()) {
            return null;
        }
Severity: Minor
Found in src/CloudFlare.php - About 2 hrs to fix

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

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

Method curlRequest has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function curlRequest($url, $data = null, $method = 'DELETE')
    {
        $curlTimeout = $this->getCurlTimeout();

        $curl = curl_init();
Severity: Minor
Found in src/CloudFlare.php - About 1 hr to fix

Function getServerName has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function getServerName()
    {
        $serverName = '';
        if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
            $serverName = Convert::raw2xml($_SERVER['HTTP_HOST']); // "Fixes" #1 (what?)
Severity: Minor
Found in src/CloudFlare.php - About 35 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 $zoneID;
Severity: Major
Found in src/CloudFlare.php - About 30 mins to fix

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 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 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

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

There are no issues that match your filters.

Category
Status