YetiForceCompany/YetiForceCRM

View on GitHub
app/Integrations/Magento/Connector/Token.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Missing class import via use statement (line '36', column '20').
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))

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 '53', column '20').
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request($method, $url, [

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 using static access to class '\App\Log' in method 'request'.
Open

        \App\Log::beginProfile("{$method}|Token::request|{$url}", 'App\Integrations\Magento');

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\Log' in method 'authorize'.
Open

        \App\Log::beginProfile("POST|Token::authorize|{$url}", 'App\Integrations\Magento');

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\RequestHttp' in method 'authorize'.
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))

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\Json' in method 'authorize'.
Open

        $this->token = \App\Json::decode((string) $response->getBody());

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\Log' in method 'authorize'.
Open

        \App\Log::endProfile("POST|Token::authorize|{$url}", 'App\Integrations\Magento');

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\RequestHttp' in method 'request'.
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request($method, $url, [

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\Log' in method 'request'.
Open

        \App\Log::endProfile("{$method}|Token::request|{$url}", 'App\Integrations\Magento');

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

Define a constant instead of duplicating this literal "App\Integrations\Magento" 4 times.
Open

        \App\Log::beginProfile("POST|Token::authorize|{$url}", 'App\Integrations\Magento');

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Call to method endProfile from undeclared class \App\Log
Open

        \App\Log::endProfile("{$method}|Token::request|{$url}", 'App\Integrations\Magento');

Call to method endProfile from undeclared class \App\Log
Open

        \App\Log::endProfile("POST|Token::authorize|{$url}", 'App\Integrations\Magento');

Call to method post from undeclared class \GuzzleHttp\Client
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))

Call to method __construct from undeclared class \GuzzleHttp\Client
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request($method, $url, [

Call to method __construct from undeclared class \GuzzleHttp\Client
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))

Call to method beginProfile from undeclared class \App\Log
Open

        \App\Log::beginProfile("POST|Token::authorize|{$url}", 'App\Integrations\Magento');

Call to method beginProfile from undeclared class \App\Log
Open

        \App\Log::beginProfile("{$method}|Token::request|{$url}", 'App\Integrations\Magento');

Call to method request from undeclared class \GuzzleHttp\Client
Open

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request($method, $url, [

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

            throw new AppException($response->getReasonPhrase(), $response->getStatusCode());

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

            'headers' => [

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

        return (string) $response->getBody();

Line exceeds 120 characters; contains 182 characters
Open

 * The file is part of the paid functionality. Using the file is allowed only after purchasing a subscription. File modification allowed only with the consent of the system producer.

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

     *

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

                'timeout' => 0,

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

        if (200 !== $response->getStatusCode()) {

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

        if (200 !== $response->getStatusCode()) {

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

    {

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

    /** {@inheritdoc} */

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

        $url = rtrim($this->config->get('url'), '/') . "/rest/$action";

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

    }

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

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request($method, $url, [

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

    private $token;

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

                'authorization' => 'Bearer ' . $this->token,

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

     * Special token to authorization.

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

    }

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

    /** {@inheritdoc} */

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

            ],

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

            'json' => $params, ]);

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

     */

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

            throw new AppException($response->getReasonPhrase(), $response->getStatusCode());

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

        $url = rtrim($this->config->get('url'), '/') . '/rest/V1/integration/admin/token';

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

        \App\Log::beginProfile("POST|Token::authorize|{$url}", 'App\Integrations\Magento');

Line exceeds 120 characters; contains 124 characters
Open

                'json' => ['username' => $this->config->get('user_name'), 'password' => $this->config->get('password')], ]);

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

        \App\Log::beginProfile("{$method}|Token::request|{$url}", 'App\Integrations\Magento');

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

        \App\Log::endProfile("POST|Token::authorize|{$url}", 'App\Integrations\Magento');

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

        $this->token = \App\Json::decode((string) $response->getBody());

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

    public function request(string $method, string $action, array $params = []): string

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

            'http_errors' => false,

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

    public function authorize()

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

                'json' => ['username' => $this->config->get('user_name'), 'password' => $this->config->get('password')], ]);

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

        \App\Log::endProfile("{$method}|Token::request|{$url}", 'App\Integrations\Magento');

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

     * @var string

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

            ->post($url, [

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

        $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))

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

                'http_errors' => false,

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

            'timeout' => 0,

There are no issues that match your filters.

Category
Status