Showing 48 of 48 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function geojsonActionGet() : array
{
$request = $this->di->get("request");
$client = $request->getServer('REMOTE_ADDR');
$ipaddress = $request->getGet("ip") ? $request->getGet("ip") : $client;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 91.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function pastDays
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function pastDays()
{
$pastDays = [];
if ($this->pastDays["data"]) {
- 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
Function daily
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function daily()
{
$days = [];
if ($this->daily) {
setlocale(LC_ALL, 'sv_SV');
- 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
The method fetchGeoInfo uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$query = [
"key" => $this->opencagekey,
"q" => $this->ipAddress,
"pretty" => "1",
- 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
The method validateIp uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->message = "$this->ipAddress är inte en giltig IP adress";
}
- 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
The method getZoomLevel uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$retArray = array("zoomLevel" => "3", "radius" => "400000");
}
- 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
The method fetchGeoInfo uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->setErrorMessage("Ingen positionsdata kunde hämtas utifrån platsnamnet.");
}
- 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
The method fetchWeatherInfo uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->setErrorMessage("DarkSkyError: daily usage limit exceeded");
}
- 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
The method fetchConcurrently uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$nodes = array();
$results = array();
$urlCount = count($urls);
- 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
The method getWeatherInfo uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return array_merge(
$this->getInfo(),
array(
"pos" => $this->ipAddress
- 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
The method fetchGeoInfo uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->setErrorMessage("Ingen positionsdata kunde hämtas utifrån platsnamnet.");
}
- 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
Line exceeds 120 characters; contains 269 characters Open
För att hämta geografisk info med mitt API görs ett GET- eller POST-anrop till ip/json. Görs ett GET-anrop måste query string ?ip=[ip-adress] finnas med. T. ex: <a href="<?php echo $url->createRelative("ip/geojson") ?>?ip=1.1.1.1">ip/geojson?ip=1.1.1.1</a>
- Exclude checks
Line exceeds 120 characters; contains 187 characters Open
<p>Svaret innehåller geografisk information om platsen du söker väder på, väderinformation om dagens väder, vädret en vecka framåt samt vädret för 30 föregående dagar.</p>
- Exclude checks
Line exceeds 120 characters; contains 262 characters Open
För att validera en ip-adress med mitt API görs ett GET- eller POST-anrop till ip/json. Görs ett GET-anrop måste query string ?ip=[ip-adress] finnas med. T. ex: <a href="<?php echo $url->createRelative("ip/json") ?>?ip=1.1.1.1">ip/json?ip=1.1.1.1</a>
- Exclude checks
Line exceeds 120 characters; contains 170 characters Open
<a href="<?php echo $url->createRelative("ip/geoinfo") ?>?ip=2001:0db8:85a3:08d3:1319:8a2e:0370:7334">Hämta från 2001:0db8:85a3:08d3:1319:8a2e:0370:7334</a>
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
<p>Lägsta temperatur: <?= $day["temperatureMin"]?>° <small>(<?=$day["apparentTemperatureMin"]?>°)</small></p>
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
<p>Lägsta temperatur: <?= $day["temperatureMin"]?>° <small>(<?=$day["apparentTemperatureMin"]?>°)</small></p>
- Exclude checks
Line exceeds 120 characters; contains 167 characters Open
<a href="<?php echo $url->createRelative("ip/validate") ?>?ip=2001:0db8:85a3:08d3:1319:8a2e:0370:7334">Validera 2001:0db8:85a3:08d3:1319:8a2e:0370:7334</a>
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
"start" => "\n\n\n" . t("Revision history") . " {#revision}\n-------------\n\n<span class=\"revision-history\">\n",
- Exclude checks
Line exceeds 120 characters; contains 171 characters Open
<a href="<?php echo $url->createRelative("ip/validate") ?>?ip=<?= $request->getServer("REMOTE_ADDR") ?>">Validera <?= $request->getServer("REMOTE_ADDR") ?></a>
- Exclude checks