PoweredLocal/vrata

View on GitHub
app/Services/RestClient.php

Summary

Maintainability
A
2 hrs
Test Coverage

Function injectBodyParams has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    private function injectBodyParams(array $body, array $params, $prefix = '')
    {
        foreach ($params as $key => $value) {
            foreach ($body as $bodyParam => $bodyValue) {
                if (is_string($value) || is_numeric($value)) {
Severity: Minor
Found in app/Services/RestClient.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 injectParams has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private function injectParams($url, array $params, $prefix = '')
    {
        foreach ($params as $key => $value) {
            if (is_array($value)) {
                $url = $this->injectParams($url, $value, $prefix . $key . '.');
Severity: Minor
Found in app/Services/RestClient.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 using undefined variables such as '$output' which will lead to PHP notices.
Open

            $output['origin%' . $key] = $value;
Severity: Minor
Found in app/Services/RestClient.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$output' which will lead to PHP notices.
Open

        return $output;
Severity: Minor
Found in app/Services/RestClient.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

The class RestClient has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
Open

class RestClient
{
    /**
     * @var Client
     */
Severity: Minor
Found in app/Services/RestClient.php by phpmd

CouplingBetweenObjects

Since: 1.1.0

A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

Example

class Foo {
    /**
     * @var \foo\bar\X
     */
    private $x = null;

    /**
     * @var \foo\bar\Y
     */
    private $y = null;

    /**
     * @var \foo\bar\Z
     */
    private $z = null;

    public function setFoo(\Foo $foo) {}
    public function setBar(\Bar $bar) {}
    public function setBaz(\Baz $baz) {}

    /**
     * @return \SplObjectStorage
     * @throws \OutOfRangeException
     * @throws \InvalidArgumentException
     * @throws \ErrorException
     */
    public function process(\Iterator $it) {}

    // ...
}

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

The closing brace for the class must go on the next line after the body
Open

}
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Each PHP statement must be on a line by itself
Open

        $wrapper->setCritical($batch->filter(function($action) { return $action->isCritical(); })->count());
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Expected 1 space after FUNCTION keyword; 0 found
Open

        $wrapper->setCritical($batch->filter(function($action) { return $action->isCritical(); })->count());
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Expected 1 space after FUNCTION keyword; 0 found
Open

        $promises = $batch->reduce(function($carry, $action) use ($parametersJar) {
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Inline control structures are not allowed
Open

            if ($wrapper->hasCriticalActions()) throw new UnableToExecuteRequestException($response);
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Inline control structures are not allowed
Open

        if ($url[0] != '/') $url = '/' . $url;
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Inline control structures are not allowed
Open

        if (isset($parametersJar['query_string'])) $url .= '?' . $parametersJar['query_string'];
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Inline control structures are not allowed
Open

        if (isset($this->guzzleParams['body'])) unset($this->guzzleParams['body']);
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Line exceeds 120 characters; contains 146 characters
Open

                'X-Token-Scopes' => $request->user() && ! empty($request->user()->token()) ? implode(',', $request->user()->token()->scopes) : '',
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Inline control structures are not allowed
Open

            if (! $response) $response = new PsrResponse(502, []);
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Closing brace indented incorrectly; expected 8 spaces, found 9
Open

         }
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Whitespace found at end of line
Open

    }    
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

}
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Usage of ELSE IF is discouraged; use ELSEIF instead
Open

                } else if (is_array($value)) {
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Closing brace must be on a line by itself
Open

        $wrapper->setCritical($batch->filter(function($action) { return $action->isCritical(); })->count());
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Opening brace must be the last content on the line
Open

        $wrapper->setCritical($batch->filter(function($action) { return $action->isCritical(); })->count());
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

Line indented incorrectly; expected 8 spaces, found 9
Open

         }
Severity: Minor
Found in app/Services/RestClient.php by phpcodesniffer

There are no issues that match your filters.

Category
Status