YetiForceCompany/YetiForceCRM

View on GitHub
app/Extension/PwnedPassword/YetiForce.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method check has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function check(string $password): array
    {
        $status = ['status' => true];
        $product = \App\YetiForce\Register::getProduct('YetiForcePassword');
        if (empty($password) || !\App\RequestUtil::isNetConnection() || empty($product['params']['login']) || empty($product['params']['pass'])) {
Severity: Minor
Found in app/Extension/PwnedPassword/YetiForce.php - About 1 hr to fix

    Function check has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function check(string $password): array
        {
            $status = ['status' => true];
            $product = \App\YetiForce\Register::getProduct('YetiForcePassword');
            if (empty($password) || !\App\RequestUtil::isNetConnection() || empty($product['params']['login']) || empty($product['params']['pass'])) {
    Severity: Minor
    Found in app/Extension/PwnedPassword/YetiForce.php - About 45 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 '50', column '31').
    Open

                        throw new \App\Exceptions\AppException('Error with response |' . $response['error']);

    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 '27').
    Open

                    throw new \App\Exceptions\AppException('Error with connection |' . $request->getReasonPhrase());

    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 '36', column '29').
    Open

                $request = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request(

    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\Language' in method 'check'.
    Open

                            'message' => \App\Language::translate('LBL_ALERT_PWNED_PASSWORD', 'Settings:Password'),

    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 'check'.
    Open

                    $response = \App\Json::decode($request->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\RequestUtil' in method 'check'.
    Open

            if (empty($password) || !\App\RequestUtil::isNetConnection() || empty($product['params']['login']) || empty($product['params']['pass'])) {

    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 'check'.
    Open

                $request = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request(

    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\YetiForce\Shop' in method 'isActive'.
    Open

            return \App\YetiForce\Shop::check('YetiForcePassword');

    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 'check'.
    Open

                \App\Log::beginProfile("POST|YetiForce::check|{$url}", __NAMESPACE__);

    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 'check'.
    Open

                \App\Log::error($ex->getMessage(), __CLASS__);

    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

    The method check uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    throw new \App\Exceptions\AppException('Error with connection |' . $request->getReasonPhrase());
                }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

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

    Avoid using static access to class '\App\YetiForce\Register' in method 'check'.
    Open

            $product = \App\YetiForce\Register::getProduct('YetiForcePassword');

    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 'check'.
    Open

                \App\Log::endProfile("POST|YetiForce::check|{$url}", __NAMESPACE__);

    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\YetiForce\Register' in method 'check'.
    Open

                    ['json' => ['sha1' => sha1($password)], 'timeout' => 2,  'http_errors' => false,  'auth' => [$product['params']['login'], $product['params']['pass']], 'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()]]

    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 "params" 4 times.
    Open

            if (empty($password) || !\App\RequestUtil::isNetConnection() || empty($product['params']['login']) || empty($product['params']['pass'])) {

    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.

    Rename "$url" which has the same name as the field declared at line 21.
    Open

                $url = 'https://passwords.yetiforce.eu/pwned';

    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

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

                $request = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request(
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

    Call to method getProduct from undeclared class \App\YetiForce\Register
    Open

            $product = \App\YetiForce\Register::getProduct('YetiForcePassword');
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

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

                \App\Log::endProfile("POST|YetiForce::check|{$url}", __NAMESPACE__);
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

    Call to method getInstanceKey from undeclared class \App\YetiForce\Register
    Open

                    ['json' => ['sha1' => sha1($password)], 'timeout' => 2,  'http_errors' => false,  'auth' => [$product['params']['login'], $product['params']['pass']], 'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()]]
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

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

                \App\Log::error($ex->getMessage(), __CLASS__);
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

    Call to method check from undeclared class \App\YetiForce\Shop
    Open

            return \App\YetiForce\Shop::check('YetiForcePassword');
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

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

                \App\Log::beginProfile("POST|YetiForce::check|{$url}", __NAMESPACE__);
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

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

                $request = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request(
    Severity: Critical
    Found in app/Extension/PwnedPassword/YetiForce.php by phan

    Line exceeds 120 characters; contains 125 characters
    Open

        public $infoUrl = 'index.php?module=YetiForce&parent=Settings&view=Shop&product=YetiForcePassword&mode=showProductModal';

    Line exceeds 120 characters; contains 236 characters
    Open

                    ['json' => ['sha1' => sha1($password)], 'timeout' => 2,  'http_errors' => false,  'auth' => [$product['params']['login'], $product['params']['pass']], 'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()]]

    Line exceeds 120 characters; contains 146 characters
    Open

            if (empty($password) || !\App\RequestUtil::isNetConnection() || empty($product['params']['login']) || empty($product['params']['pass'])) {

    There are no issues that match your filters.

    Category
    Status