avalanche-development/swagger-router-middleware

View on GitHub
src/Router.php

Summary

Maintainability
B
4 hrs
Test Coverage

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

class Router implements LoggerAwareInterface
{

    use LoggerAwareTrait;

Severity: Minor
Found in src/Router.php by phpmd

Method __invoke has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function __invoke(Request $request, Response $response, callable $next)
    {
        $this->log('start');

        if ($this->isDocumentationRoute($request)) {
Severity: Minor
Found in src/Router.php - About 1 hr to fix

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

        public function __invoke(Request $request, Response $response, callable $next)
        {
            $this->log('start');
    
            if ($this->isDocumentationRoute($request)) {
    Severity: Minor
    Found in src/Router.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 getSecurity has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function getSecurity(array $operation)
        {
            $securityRequirement = [];
    
            if (isset($operation['security'])) {
    Severity: Minor
    Found in src/Router.php - About 55 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 resolveRefs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function resolveRefs(array $chunk)
        {
            $resolvedChunk = [];
            foreach ($chunk as $key => $value) {
                if ($key === '$ref') {
    Severity: Minor
    Found in src/Router.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

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

        protected function getParameters(array $pathItem, array $operation)
        {
            $uniqueParameters = [];
            if (array_key_exists('parameters', $pathItem)) {
                foreach ($pathItem['parameters'] as $parameter) {
    Severity: Minor
    Found in src/Router.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

    Missing class import via use statement (line '269', column '27').
    Open

                    throw new \Exception('Security scheme is not defined');
    Severity: Minor
    Found in src/Router.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

    Missing class import via use statement (line '174', column '23').
    Open

                throw new \Exception('invalid json reference found in swagger');
    Severity: Minor
    Found in src/Router.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

    Missing class import via use statement (line '183', column '27').
    Open

                    throw new \Exception('reference not found in swagger');
    Severity: Minor
    Found in src/Router.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

    Missing class import via use statement (line '54', column '27').
    Open

                    throw new \Exception('Invalid swagger - could not decode');
    Severity: Minor
    Found in src/Router.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

    Missing class import via use statement (line '261', column '23').
    Open

                throw new \Exception('No security schemes defined');
    Severity: Minor
    Found in src/Router.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

    Avoid unused parameters such as '$request'.
    Open

        protected function encodeResponse(Request $request, Response $response)
    Severity: Minor
    Found in src/Router.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

    There are no issues that match your filters.

    Category
    Status