Missing class import via use statement (line '35', column '21'). Open
$response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url);
- Read upRead up
- Exclude checks
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());
- Read upRead up
- Exclude checks
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()) {
- Read upRead up
- Exclude checks
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__);
- Read upRead up
- Exclude checks
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__);
- Read upRead up
- Exclude checks
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());
}
- Read upRead up
- Exclude checks
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__);
- Read upRead up
- Exclude checks
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());
- Read upRead up
- Exclude checks
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']];
}
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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']];
}
- Read upRead up
- Exclude checks
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__);
- Exclude checks
Call to method __construct
from undeclared class \GuzzleHttp\Client
Open
$response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url);
- Exclude checks
Call to method request
from undeclared class \GuzzleHttp\Client
Open
$response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url);
- Exclude checks
Call to method error
from undeclared class \App\Log
Open
\App\Log::error('Error - ' . $ex->getMessage(), __CLASS__);
- Exclude checks
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']];
- Exclude checks
Call to method beginProfile
from undeclared class \App\Log
Open
\App\Log::beginProfile("GET|Nominatim::getCoordinates|{$url}", __NAMESPACE__);
- Exclude checks
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']];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $coordinates;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::beginProfile("GET|Nominatim::getCoordinates|{$url}", __NAMESPACE__);
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (200 === $response->getStatusCode()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($addressInfo) || !\App\RequestUtil::isNetConnection()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $coordinates;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
], $addressInfo));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::error('Error - ' . $ex->getMessage(), __CLASS__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$coordinates = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'format' => 'json',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getCoordinatesByValue(string $value): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['lat' => $coordinates['lat'], 'lon' => $coordinates['lon']];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'addressdetails' => 1,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Exception $ex) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$coordinates = \App\Json::decode($response->getBody());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getCoordinates(array $addressInfo)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::endProfile("GET|Nominatim::getCoordinates|{$url}", __NAMESPACE__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) {
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
if (($coordinatesDetails = $this->getCoordinates(['q' => $value])) && ($coordinates = reset($coordinatesDetails)) && !empty($coordinates)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url = $this->url . '/?' . \http_build_query(array_merge([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'limit' => 1,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks