YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/Core/Request.php

Summary

Maintainability
A
0 mins
Test Coverage
C
72%

init accesses the super-global variable $_SERVER.
Open

    public static function init($request = false)
    {
        if (!static::$request) {
            static::$request = new self($request ?: $_REQUEST);
            static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');
Severity: Minor
Found in api/webservice/Core/Request.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

init accesses the super-global variable $_REQUEST.
Open

    public static function init($request = false)
    {
        if (!static::$request) {
            static::$request = new self($request ?: $_REQUEST);
            static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');
Severity: Minor
Found in api/webservice/Core/Request.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

Missing class import via use statement (line '135', column '14').
Open

            throw new \App\Exceptions\AppException('Private Key failed');
Severity: Minor
Found in api/webservice/Core/Request.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

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

    public static function init($request = false)
Severity: Minor
Found in api/webservice/Core/Request.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

Avoid using static access to class '\App\Utils' in method 'loadData'.
Open

        $this->rawValues = \App\Utils::merge($this->contentParse($content), $this->rawValues);
Severity: Minor
Found in api/webservice/Core/Request.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid using static access to class '\App\Config' in method 'loadData'.
Open

        if (\App\Config::api('ENCRYPT_DATA_TRANSFER') && $encrypted && 1 === (int) $encrypted) {
Severity: Minor
Found in api/webservice/Core/Request.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid using static access to class '\App\Config' in method 'decryptData'.
Open

        $privateKey = 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PRIVATE_KEY');
Severity: Minor
Found in api/webservice/Core/Request.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

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

    public function decryptData(string $data): string
    {
        $privateKey = 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PRIVATE_KEY');
        if (!$privateKey = openssl_pkey_get_private($privateKey)) {
            throw new \App\Exceptions\AppException('Private Key failed');
Severity: Minor
Found in api/webservice/Core/Request.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

Rename "$content" which has the same name as the field declared at line 24.
Open

        $content = file_get_contents('php://input');
Severity: Major
Found in api/webservice/Core/Request.php by sonar-php

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Add a "case default" clause to this "switch" statement.
Open

        switch ($type) {
Severity: Critical
Found in api/webservice/Core/Request.php by sonar-php

The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

Noncompliant Code Example

switch ($param) {  //missing default clause
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

switch ($param) {
  default: // default clause should be the last one
    error();
    break;
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
}

Compliant Solution

switch ($param) {
  case 0:
    do_something();
    break;
  case 1:
    do_something_else();
    break;
  default:
    error();
    break;
}

See

  • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
  • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
  • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
  • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
  • MISRA C:2012, 16.1 - All switch statements shall be well-formed
  • MISRA C:2012, 16.4 - Every switch statement shall have a default label
  • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
  • MITRE, CWE-478 - Missing Default Case in Switch Statement
  • CERT, MSC01-C. - Strive for logical completeness
  • CERT, MSC01-CPP. - Strive for logical completeness

Argument 2 (assoc) is 1 but \json_decode() takes bool
Open

                $return = json_decode($content, 1);
Severity: Minor
Found in api/webservice/Core/Request.php by phan

Assigning ?array|?array{}|?bool|?float|?int|?string to property but \Api\Core\Request->content is array
Open

        return $this->content = $return;
Severity: Minor
Found in api/webservice/Core/Request.php by phan

Call to method parse from undeclared class \Notihnio\MultipartFormDataParser\MultipartFormDataParser
Open

                $return = \Notihnio\MultipartFormDataParser\MultipartFormDataParser::parse()->params;
Severity: Critical
Found in api/webservice/Core/Request.php by phan

Returning type ?array|?array{}|?bool|?float|?int|?string but contentParse() is declared to return array
Open

        return $this->content = $return;
Severity: Minor
Found in api/webservice/Core/Request.php by phan

Argument 1 (key) is resource but \openssl_pkey_get_private() takes string
Open

        $privateKey = openssl_pkey_get_private($privateKey);
Severity: Minor
Found in api/webservice/Core/Request.php by phan

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-header-fields' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param bool|array $request

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        switch ($type) {

Spaces must be used to indent lines; tabs are not allowed
Open

        return array_map('\App\Purifier::purify', array_keys($this->content));

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $privateKey = 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PRIVATE_KEY');

Spaces must be used to indent lines; tabs are not allowed
Open

    public $contentType;

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-parent-id' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

                static::$request->contentType = static::$request->getHeader('accept');

Spaces must be used to indent lines; tabs are not allowed
Open

        return static::$request;

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        $encrypted = $this->getHeader('encrypted');

Spaces must be used to indent lines; tabs are not allowed
Open

        $content = file_get_contents('php://input');

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

            return $this;

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

            case 'json':

Spaces must be used to indent lines; tabs are not allowed
Open

            case 'x-www-form-urlencoded':

Spaces must be used to indent lines; tabs are not allowed
Open

        openssl_private_decrypt($data, $decrypted, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-row-limit' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return $this

Spaces must be used to indent lines; tabs are not allowed
Open

        if ('GET' === self::getRequestMethod()) {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-unit-price' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-unit-gross' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return Request

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

            $type = explode('/', (explode(';', $type)[0]));

Spaces must be used to indent lines; tabs are not allowed
Open

        $return = [];

Spaces must be used to indent lines; tabs are not allowed
Open

                break;

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        'encrypted' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-token' => \App\Purifier::ALNUM,

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-row-offset' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

     * Static instance initialization.

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!static::$request) {

Spaces must be used to indent lines; tabs are not allowed
Open

            static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

            case 'form-data':

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var array List of headings and sanitization methods. */

Spaces must be used to indent lines; tabs are not allowed
Open

    public $headersPurifierMap = [

Spaces must be used to indent lines; tabs are not allowed
Open

     * Load data from request.

Spaces must be used to indent lines; tabs are not allowed
Open

        if (empty($content)) {

Spaces must be used to indent lines; tabs are not allowed
Open

     * Parsing the content of the request.

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-only-column' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-cv-id' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

        $this->rawValues = \App\Utils::merge($this->contentParse($content), $this->rawValues);

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->content = $return;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function init($request = false)

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    public function loadData(): self

Spaces must be used to indent lines; tabs are not allowed
Open

                break;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var array The content of the request. */

Spaces must be used to indent lines; tabs are not allowed
Open

        if (\App\Config::api('ENCRYPT_DATA_TRANSFER') && $encrypted && 1 === (int) $encrypted) {

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string $content

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!empty($type)) {

Spaces must be used to indent lines; tabs are not allowed
Open

     * Get key of the content request.

Spaces must be used to indent lines; tabs are not allowed
Open

     * Decrypt content of the request.

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var string Requested content type. */

Spaces must be used to indent lines; tabs are not allowed
Open

            if (empty(static::$request->contentType)) {

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array

Spaces must be used to indent lines; tabs are not allowed
Open

    public function decryptData(string $data): string

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new \App\Exceptions\AppException('Private Key failed');

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-product-bundles' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-start-with' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-row-count' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

            return $this;

Spaces must be used to indent lines; tabs are not allowed
Open

            $content = $this->decryptData($content);

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this;

Spaces must be used to indent lines; tabs are not allowed
Open

    private function contentParse(string $content): array

Spaces must be used to indent lines; tabs are not allowed
Open

        $type = $this->contentType;

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        'authorization' => \App\Purifier::ALNUM_EXTENDED,

Spaces must be used to indent lines; tabs are not allowed
Open

            static::$request = new self($request ?: $_REQUEST);

Spaces must be used to indent lines; tabs are not allowed
Open

            $type = array_pop($type);

Spaces must be used to indent lines; tabs are not allowed
Open

                $return = json_decode($content, 1);

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-raw-data' => \App\Purifier::INTEGER,

Spaces must be used to indent lines; tabs are not allowed
Open

    ];

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

        $privateKey = openssl_pkey_get_private($privateKey);

Spaces must be used to indent lines; tabs are not allowed
Open

        'x-api-key' => \App\Purifier::ALNUM,

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getContentKeys(): array

Spaces must be used to indent lines; tabs are not allowed
Open

        return $decrypted;

Spaces must be used to indent lines; tabs are not allowed
Open

    public $content = [];

Line exceeds 120 characters; contains 168 characters
Open

            static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');

Spaces must be used to indent lines; tabs are not allowed
Open

                $return = \Notihnio\MultipartFormDataParser\MultipartFormDataParser::parse()->params;

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string $data

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!$privateKey = openssl_pkey_get_private($privateKey)) {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

There are no issues that match your filters.

Category
Status