Method calculate
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function calculate()
{
if (!\App\RequestUtil::isNetConnection()) {
throw new \App\Exceptions\AppException('ERR_NO_INTERNET_CONNECTION');
}
Function calculate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function calculate()
{
if (!\App\RequestUtil::isNetConnection()) {
throw new \App\Exceptions\AppException('ERR_NO_INTERNET_CONNECTION');
}
- Read upRead up
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 '41', column '14'). Open
throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody(), 500);
- 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 '33', column '20'). 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 '26', column '14'). Open
throw new \App\Exceptions\AppException('ERR_NO_INTERNET_CONNECTION');
- 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\RequestHttp' in method 'calculate'. 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 using static access to class '\App\Log' in method 'calculate'. Open
\App\Log::endProfile("GET|OsrmRouting::calculate|{$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
The method calculate 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(), 500);
}
- 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 'calculate'. Open
\App\Log::beginProfile("GET|OsrmRouting::calculate|{$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 'calculate'. Open
$json = \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 using static access to class '\App\RequestUtil' in method 'calculate'. Open
if (!\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
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 endProfile
from undeclared class \App\Log
Open
\App\Log::endProfile("GET|OsrmRouting::calculate|{$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 beginProfile
from undeclared class \App\Log
Open
\App\Log::beginProfile("GET|OsrmRouting::calculate|{$url}", __NAMESPACE__);
- 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
'http_errors' => false,
- 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
$this->distance += $route['distance'] / 1000;
- 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
\App\Log::endProfile("GET|OsrmRouting::calculate|{$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
'geometries' => 'geojson',
- 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
throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody(), 500);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->travelTime += $route['duration'];
- 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
$response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\App\RequestUtil::isNetConnection()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'steps' => 'true',
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
throw new \App\Exceptions\AppException('Error with connection |' . $response->getReasonPhrase() . '|' . $response->getBody(), 500);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($json['routes'] as $route) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function calculate()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$json = \App\Json::decode($response->getBody());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$coordinates = array_merge($coordinates, $route['geometry']['coordinates']);
- 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
throw new \App\Exceptions\AppException('ERR_NO_INTERNET_CONNECTION');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url = $this->url . '/route/v1/car/' . implode(';', $this->parsePoints()) . '?' . http_build_query([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($json['routes'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::beginProfile("GET|OsrmRouting::calculate|{$url}", __NAMESPACE__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'timeout' => 120,
- 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
$coordinates = [];
- 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
'type' => 'LineString',
- 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
$tracks[] = $this->end['lon'] . ',' . $this->end['lat'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->start['lon'] . ',' . $this->start['lat'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($this->indirectPoints)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'coordinates' => $coordinates,
- 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
$tracks = [
- 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
return $tracks;
- 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
$this->geoJson = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function parsePoints(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->indirectPoints as $tempLon) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tracks[] = $tempLon['lon'] . ',' . $tempLon['lat'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks