yiisoft/yii2

View on GitHub
framework/web/ErrorHandler.php

Summary

Maintainability
C
1 day
Test Coverage

createServerInformationLink accesses the super-global variable $_SERVER.
Open

    public function createServerInformationLink()
    {
        $serverUrls = [
            'https://httpd.apache.org/' => ['apache'],
            'https://nginx.org/' => ['nginx'],
Severity: Minor
Found in framework/web/ErrorHandler.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

createServerInformationLink accesses the super-global variable $_SERVER.
Open

    public function createServerInformationLink()
    {
        $serverUrls = [
            'https://httpd.apache.org/' => ['apache'],
            'https://nginx.org/' => ['nginx'],
Severity: Minor
Found in framework/web/ErrorHandler.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

createServerInformationLink accesses the super-global variable $_SERVER.
Open

    public function createServerInformationLink()
    {
        $serverUrls = [
            'https://httpd.apache.org/' => ['apache'],
            'https://nginx.org/' => ['nginx'],
Severity: Minor
Found in framework/web/ErrorHandler.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

renderRequest accesses the super-global variable $GLOBALS.
Open

    public function renderRequest()
    {
        $request = '';
        foreach ($this->displayVars as $name) {
            if (!empty($GLOBALS[$name])) {
Severity: Minor
Found in framework/web/ErrorHandler.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

renderRequest accesses the super-global variable $GLOBALS.
Open

    public function renderRequest()
    {
        $request = '';
        foreach ($this->displayVars as $name) {
            if (!empty($GLOBALS[$name])) {
Severity: Minor
Found in framework/web/ErrorHandler.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

The class ErrorHandler has 11 public methods. Consider refactoring ErrorHandler to keep number of public methods under 10.
Open

class ErrorHandler extends \yii\base\ErrorHandler
{
    /**
     * @var int maximum number of source code lines to be displayed. Defaults to 19.
     */
Severity: Minor
Found in framework/web/ErrorHandler.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

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

The class ErrorHandler has an overall complexity of 90 which is very high. The configured complexity threshold is 50.
Open

class ErrorHandler extends \yii\base\ErrorHandler
{
    /**
     * @var int maximum number of source code lines to be displayed. Defaults to 19.
     */
Severity: Minor
Found in framework/web/ErrorHandler.php by phpmd

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

    public function argumentsToString($args)
    {
        $count = 0;
        $isAssoc = $args !== array_values($args);

Severity: Minor
Found in framework/web/ErrorHandler.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

Function renderException has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    protected function renderException($exception)
    {
        if (Yii::$app->has('response')) {
            $response = Yii::$app->getResponse();
            // reset parameters of response to avoid interference with partially created response data
Severity: Minor
Found in framework/web/ErrorHandler.php - About 2 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

Function convertExceptionToArray has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    protected function convertExceptionToArray($exception)
    {
        if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
            $exception = new HttpException(500, Yii::t('yii', 'An internal server error occurred.'));
        }
Severity: Minor
Found in framework/web/ErrorHandler.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 addTypeLinks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function addTypeLinks($code)
    {
        if (preg_match('/(.*?)::([^(]+)/', $code, $matches)) {
            $class = $matches[1];
            $method = $matches[2];
Severity: Minor
Found in framework/web/ErrorHandler.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 createServerInformationLink has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function createServerInformationLink()
    {
        $serverUrls = [
            'https://httpd.apache.org/' => ['apache'],
            'https://nginx.org/' => ['nginx'],
Severity: Minor
Found in framework/web/ErrorHandler.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 renderCallStackItem has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function renderCallStackItem($file, $line, $class, $method, $args, $index)
Severity: Minor
Found in framework/web/ErrorHandler.php - About 45 mins to fix

    The method renderException() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
    Open

        protected function renderException($exception)
        {
            if (Yii::$app->has('response')) {
                $response = Yii::$app->getResponse();
                // reset parameters of response to avoid interference with partially created response data
    Severity: Minor
    Found in framework/web/ErrorHandler.php by phpmd

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

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

    The method convertExceptionToArray() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
    Open

        protected function convertExceptionToArray($exception)
        {
            if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
                $exception = new HttpException(500, Yii::t('yii', 'An internal server error occurred.'));
            }
    Severity: Minor
    Found in framework/web/ErrorHandler.php by phpmd

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

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

    The method argumentsToString() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
    Open

        public function argumentsToString($args)
        {
            $count = 0;
            $isAssoc = $args !== array_values($args);
    
    
    Severity: Minor
    Found in framework/web/ErrorHandler.php by phpmd

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

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

    Missing class import via use statement (line '208', column '31').
    Open

                $reflection = new \ReflectionClass($class);
    Severity: Minor
    Found in framework/web/ErrorHandler.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

    Remove error control operator '@' on line 305.
    Open

        public function renderCallStackItem($file, $line, $class, $method, $args, $index)
        {
            $lines = [];
            $begin = $end = 0;
            if ($file !== null && $line !== null) {
    Severity: Minor
    Found in framework/web/ErrorHandler.php by phpmd

    ErrorControlOperator

    Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

    Example

    function foo($filePath) {
        $file = @fopen($filPath); // hides exceptions
        $key = @$array[$notExistingKey]; // assigns null to $key
    }

    Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

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

        public function renderCallStackItem($file, $line, $class, $method, $args, $index)
        {
            $lines = [];
            $begin = $end = 0;
            if ($file !== null && $line !== null) {
    Severity: Minor
    Found in framework/web/ErrorHandler.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 '170', column '14').
    Open

        protected function convertExceptionToArray($exception)
        {
            if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
                $exception = new HttpException(500, Yii::t('yii', 'An internal server error occurred.'));
            }
    Severity: Minor
    Found in framework/web/ErrorHandler.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 '282', column '14').
    Open

        public function renderPreviousExceptions($exception)
        {
            if (($previous = $exception->getPrevious()) !== null) {
                return $this->renderFile($this->previousExceptionView, ['exception' => $previous]);
            }
    Severity: Minor
    Found in framework/web/ErrorHandler.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 parameter $_file_ is not named in camelCase.
    Open

        public function renderFile($_file_, $_params_)
        {
            $_params_['handler'] = $this;
            if ($this->exception instanceof ErrorException || !Yii::$app->has('view')) {
                ob_start();
    Severity: Minor
    Found in framework/web/ErrorHandler.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 parameter $_params_ is not named in camelCase.
    Open

        public function renderFile($_file_, $_params_)
        {
            $_params_['handler'] = $this;
            if ($this->exception instanceof ErrorException || !Yii::$app->has('view')) {
                ob_start();
    Severity: Minor
    Found in framework/web/ErrorHandler.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 $_params_ is not named in camelCase.
    Open

        public function renderFile($_file_, $_params_)
        {
            $_params_['handler'] = $this;
            if ($this->exception instanceof ErrorException || !Yii::$app->has('view')) {
                ob_start();
    Severity: Minor
    Found in framework/web/ErrorHandler.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 $_params_ is not named in camelCase.
    Open

        public function renderFile($_file_, $_params_)
        {
            $_params_['handler'] = $this;
            if ($this->exception instanceof ErrorException || !Yii::$app->has('view')) {
                ob_start();
    Severity: Minor
    Found in framework/web/ErrorHandler.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 $_file_ is not named in camelCase.
    Open

        public function renderFile($_file_, $_params_)
        {
            $_params_['handler'] = $this;
            if ($this->exception instanceof ErrorException || !Yii::$app->has('view')) {
                ob_start();
    Severity: Minor
    Found in framework/web/ErrorHandler.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 $_params_ is not named in camelCase.
    Open

        public function renderFile($_file_, $_params_)
        {
            $_params_['handler'] = $this;
            if ($this->exception instanceof ErrorException || !Yii::$app->has('view')) {
                ob_start();
    Severity: Minor
    Found in framework/web/ErrorHandler.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 $_file_ is not named in camelCase.
    Open

        public function renderFile($_file_, $_params_)
        {
            $_params_['handler'] = $this;
            if ($this->exception instanceof ErrorException || !Yii::$app->has('view')) {
                ob_start();
    Severity: Minor
    Found in framework/web/ErrorHandler.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