YetiForceCompany/YetiForceCRM

View on GitHub
app/Map/Coordinates/YetiForce.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method getCoordinates has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getCoordinates(array $addressInfo)
    {
        $product = \App\YetiForce\Register::getProduct('YetiForceMap');
        if (empty($addressInfo) || !\App\RequestUtil::isNetConnection() || ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token']))) {
            return false;
Severity: Minor
Found in app/Map/Coordinates/YetiForce.php - About 1 hr to fix

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

        public function getCoordinates(array $addressInfo)
        {
            $product = \App\YetiForce\Register::getProduct('YetiForceMap');
            if (empty($addressInfo) || !\App\RequestUtil::isNetConnection() || ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token']))) {
                return false;
    Severity: Minor
    Found in app/Map/Coordinates/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 '49', column '30').
    Open

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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 \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody());
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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 using static access to class '\App\Log' in method 'getCoordinates'.
    Open

                \App\Log::endProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__);
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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\Json' in method 'getCoordinates'.
    Open

                    $coordinates = \App\Json::decode($response->getBody());
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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

    The method getCoordinates 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 |' . $response->getReasonPhrase() . '|' . $response->getBody());
                }
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.php by phpmd

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

                \App\Log::error('Error - ' . $ex->getMessage(), __CLASS__);
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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

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

            } else {
                $options['auth'] = [$product['params']['login'], $product['params']['pass']];
            }
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.php by phpmd

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

                \App\Log::beginProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__);
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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\YetiForce\Register' in method 'getCoordinates'.
    Open

                'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()],
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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 '65', column '80').
    Open

        public function getCoordinatesByValue(string $value): array
        {
            if (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) {
                return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']];
            }
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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

    Avoid using static access to class '\App\RequestUtil' in method 'getCoordinates'.
    Open

            if (empty($addressInfo) || !\App\RequestUtil::isNetConnection() || ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token']))) {
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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 'getCoordinates'.
    Open

                'accept-language' => \App\Language::getLanguage() . ',' . \App\Config::main('default_language') . ',en-US',
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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 '65', column '14').
    Open

        public function getCoordinatesByValue(string $value): array
        {
            if (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) {
                return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']];
            }
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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

    Avoid using static access to class '\App\RequestHttp' in method 'getCoordinates'.
    Open

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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\YetiForce\Register' in method 'getCoordinates'.
    Open

            $product = \App\YetiForce\Register::getProduct('YetiForceMap');
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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\Language' in method 'getCoordinates'.
    Open

                'accept-language' => \App\Language::getLanguage() . ',' . \App\Config::main('default_language') . ',en-US',
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.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

    Define a constant instead of duplicating this literal "params" 7 times.
    Open

            if (empty($addressInfo) || !\App\RequestUtil::isNetConnection() || ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token']))) {
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by sonar-php

    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.

    Define a constant instead of duplicating this literal "token" 3 times.
    Open

            if (empty($addressInfo) || !\App\RequestUtil::isNetConnection() || ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token']))) {
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by sonar-php

    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 getInstanceKey from undeclared class \App\YetiForce\Register
    Open

                'headers' => ['InsKey' => \App\YetiForce\Register::getInstanceKey()],
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by phan

    When fetching an array index from a value of type string, found an array index of type 'lon', but expected the index to be of type int
    Open

                return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']];
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.php by phan

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

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by phan

    When fetching an array index from a value of type string, found an array index of type 'lat', but expected the index to be of type int
    Open

                return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']];
    Severity: Minor
    Found in app/Map/Coordinates/YetiForce.php by phan

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

                \App\Log::beginProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__);
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by phan

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

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by phan

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

                \App\Log::endProfile("GET|YetiForce::getCoordinates|{$url}", __NAMESPACE__);
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by phan

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

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

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

            $product = \App\YetiForce\Register::getProduct('YetiForceMap');
    Severity: Critical
    Found in app/Map/Coordinates/YetiForce.php by phan

    Line exceeds 120 characters; contains 142 characters
    Open

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

    Line exceeds 120 characters; contains 148 characters
    Open

            if (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) {

    Line exceeds 120 characters; contains 191 characters
    Open

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

    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.

    There are no issues that match your filters.

    Category
    Status