H4MSK1/anax-weather

View on GitHub

Showing 29 of 29 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    "items" => [
        [
            "text" => "Hem",
            "url" => "",
            "title" => "Första sidan, börja här.",
Severity: Major
Found in config/navbar/header.php and 1 other location - About 3 hrs to fix
config/navbar/responsive.php on lines 12..52

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 151.

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

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    "items" => [
        [
            "text" => "Hem",
            "url" => "",
            "title" => "Första sidan, börja här.",
Severity: Major
Found in config/navbar/responsive.php and 1 other location - About 3 hrs to fix
config/navbar/header.php on lines 11..51

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 151.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

namespace H4MSK1\IpLocator;

use Anax\Commons\ContainerInjectableInterface;
Severity: Major
Found in src/IpLocator/IpLocatorController.php and 1 other location - About 2 hrs to fix
src/IpValidator/IpValidatorController.php on lines 1..29

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 130.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

namespace H4MSK1\IpValidator;

use Anax\Commons\ContainerInjectableInterface;
Severity: Major
Found in src/IpValidator/IpValidatorController.php and 1 other location - About 2 hrs to fix
src/IpLocator/IpLocatorController.php on lines 1..29

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 130.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

namespace H4MSK1\IpValidator;

use Anax\Commons\ContainerInjectableInterface;
Severity: Major
Found in src/IpValidator/IpValidatorApiController.php and 1 other location - About 1 hr to fix
src/IpLocator/IpLocatorApiController.php on lines 1..29

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 109.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

namespace H4MSK1\IpLocator;

use Anax\Commons\ContainerInjectableInterface;
Severity: Major
Found in src/IpLocator/IpLocatorApiController.php and 1 other location - About 1 hr to fix
src/IpValidator/IpValidatorApiController.php on lines 1..29

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 109.

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

Further Reading

Function processRequest has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function processRequest($iplocation, $coords, $type, Api $curl)
    {
        $payload = ['weather' => [], 'map' => null];
        $lat = 0;
        $lng = 0;
Severity: Minor
Found in src/Weather/Weather.php - About 1 hr 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

Avoid using undefined variables such as '$days' which will lead to PHP notices.
Open

            $days[$i] = strtotime("-$i days");
Severity: Minor
Found in src/Curl/Traits/WeatherApiTrait.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$days' which will lead to PHP notices.
Open

            curl_setopt($curlHandlers[$i], CURLOPT_URL, str_replace('{{day}}', $days[($i + 1)], $endpoint));
Severity: Minor
Found in src/Curl/Traits/WeatherApiTrait.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Method normalizeForecast has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function normalizeForecast($data)
    {
        $newData = [];

        if (array_key_exists('daily', $data)) {
Severity: Minor
Found in src/Curl/Traits/WeatherApiTrait.php - About 1 hr to fix

    Method processRequest has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function processRequest($iplocation, $coords, $type, Api $curl)
        {
            $payload = ['weather' => [], 'map' => null];
            $lat = 0;
            $lng = 0;
    Severity: Minor
    Found in src/Weather/Weather.php - About 1 hr to fix

      Method fetchWeatherHistory has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function fetchWeatherHistory($lat, $lng, $pastDays = 30)
          {
              $service = $this->getServiceByName('darksky');
              $endpoint = "{$service['endpoint']}{$service['key']}/{$lat},{$lng},{{day}}?lang=sv&units=si";
      
      
      Severity: Minor
      Found in src/Curl/Traits/WeatherApiTrait.php - About 1 hr to fix

        Avoid variables with short names like $di. Configured minimum length is 3.
        Open

            public function __construct(array $endpoints = [], $di = null)
        Severity: Minor
        Found in src/Curl/Api.php by phpmd

        ShortVariable

        Since: 0.2

        Detects when a field, local, or parameter has a very short name.

        Example

        class Something {
            private $q = 15; // VIOLATION - Field
            public static function main( array $as ) { // VIOLATION - Formal
                $r = 20 + $this->q; // VIOLATION - Local
                for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                    $r += $this->q;
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#shortvariable

        Avoid variables with short names like $di. Configured minimum length is 3.
        Open

            private $di;
        Severity: Minor
        Found in src/Curl/Api.php by phpmd

        ShortVariable

        Since: 0.2

        Detects when a field, local, or parameter has a very short name.

        Example

        class Something {
            private $q = 15; // VIOLATION - Field
            public static function main( array $as ) { // VIOLATION - Formal
                $r = 20 + $this->q; // VIOLATION - Local
                for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                    $r += $this->q;
                }
            }
        }

        Source https://phpmd.org/rules/naming.html#shortvariable

        A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 9 and the first side effect is on line 24.
        Open

        <?php
        Severity: Minor
        Found in config/commons.php by phpcodesniffer

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                        $newData[] = [
                            'summary' => $day['summary'],
                            'temperatureMin' => $day['temperatureMin'],
                            'temperatureMax' => $day['temperatureMax'],
                            'sunriseTime' => gmdate('H:i', $day['sunriseTime']),
        Severity: Minor
        Found in src/Curl/Traits/WeatherApiTrait.php and 1 other location - About 40 mins to fix
        src/Curl/Traits/WeatherApiTrait.php on lines 70..77

        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 94.

        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

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                        $newData[] = [
                            'summary' => $day['summary'],
                            'temperatureMin' => $day['temperatureMin'],
                            'temperatureMax' => $day['temperatureMax'],
                            'sunriseTime' => gmdate('H:i', $day['sunriseTime']),
        Severity: Minor
        Found in src/Curl/Traits/WeatherApiTrait.php and 1 other location - About 40 mins to fix
        src/Curl/Traits/WeatherApiTrait.php on lines 82..89

        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 94.

        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

        Further Reading

        Function normalizeForecast has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            public function normalizeForecast($data)
            {
                $newData = [];
        
                if (array_key_exists('daily', $data)) {
        Severity: Minor
        Found in src/Curl/Traits/WeatherApiTrait.php - About 25 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

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

                } else {
                    return $this->normalizeForecast($this->fetchWeatherHistory($lat, $lng));
                }
        Severity: Minor
        Found in src/Curl/Traits/WeatherApiTrait.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

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

                } else {
                    foreach ($data as $day) {
                        $day = $day['daily']['data'][0];
                        $newData[] = [
                            'summary' => $day['summary'],
        Severity: Minor
        Found in src/Curl/Traits/WeatherApiTrait.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

        Severity
        Category
        Status
        Source
        Language