YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Missing class import via use statement (line '35', column '21').
Open

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

                throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody());
Severity: Minor
Found in app/Map/Coordinates/Nominatim.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\RequestUtil' in method 'getCoordinates'.
Open

        if (empty($addressInfo) || !\App\RequestUtil::isNetConnection()) {
Severity: Minor
Found in app/Map/Coordinates/Nominatim.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\Log' in method 'getCoordinates'.
Open

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

            \App\Log::error('Error - ' . $ex->getMessage(), __CLASS__);
Severity: Minor
Found in app/Map/Coordinates/Nominatim.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/Nominatim.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::endProfile("GET|Nominatim::getCoordinates|{$url}", __NAMESPACE__);
Severity: Minor
Found in app/Map/Coordinates/Nominatim.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/Nominatim.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 '51', column '8').
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/Nominatim.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);
Severity: Minor
Found in app/Map/Coordinates/Nominatim.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 '51', column '74').
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/Nominatim.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

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

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

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

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

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

            $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url);
Severity: Critical
Found in app/Map/Coordinates/Nominatim.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/Nominatim.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/Nominatim.php by phan

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

            \App\Log::beginProfile("GET|Nominatim::getCoordinates|{$url}", __NAMESPACE__);
Severity: Critical
Found in app/Map/Coordinates/Nominatim.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/Nominatim.php by phan

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 $coordinates;

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

            \App\Log::beginProfile("GET|Nominatim::getCoordinates|{$url}", __NAMESPACE__);

Line exceeds 120 characters; contains 142 characters
Open

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

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

        try {

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

        if (empty($addressInfo) || !\App\RequestUtil::isNetConnection()) {

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

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

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

            $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url);

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

        return $coordinates;

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

        }

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

        ], $addressInfo));

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

            } else {

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

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

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

        $coordinates = false;

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

            'format' => 'json',

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

    public function getCoordinatesByValue(string $value): array

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

            return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']];

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

            'addressdetails' => 1,

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

        } catch (\Exception $ex) {

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

                $coordinates = \App\Json::decode($response->getBody());

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

    public function getCoordinates(array $addressInfo)

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

            \App\Log::endProfile("GET|Nominatim::getCoordinates|{$url}", __NAMESPACE__);

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 (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) {

Line exceeds 120 characters; contains 148 characters
Open

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

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

        $url = $this->url . '/?' . \http_build_query(array_merge([

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

            'limit' => 1,

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

    }

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

        }

There are no issues that match your filters.

Category
Status