Sibyx/phpGPX

View on GitHub

Showing 343 of 345 total issues

Avoid excessively long variable names like $cumulativeElevationLoss. Keep variable name length under 20.
Open

        $cumulativeElevationLoss = 0;

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

Avoid excessively long variable names like $ELEVATION_SMOOTHING_THRESHOLD. Keep variable name length under 20.
Open

    public static $ELEVATION_SMOOTHING_THRESHOLD = 2;
Severity: Minor
Found in src/phpGPX/phpGPX.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

Avoid excessively long variable names like $DATETIME_TIMEZONE_OUTPUT. Keep variable name length under 20.
Open

    public static $DATETIME_TIMEZONE_OUTPUT = 'UTC';
Severity: Minor
Found in src/phpGPX/phpGPX.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

Avoid excessively long variable names like $cumulativeElevationLoss. Keep variable name length under 20.
Open

    public $cumulativeElevationLoss = null;
Severity: Minor
Found in src/phpGPX/Models/Stats.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

Avoid excessively long variable names like $APPLY_ELEVATION_SMOOTHING. Keep variable name length under 20.
Open

    public static $APPLY_ELEVATION_SMOOTHING = false;
Severity: Minor
Found in src/phpGPX/phpGPX.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

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

                    default:
                        if (!in_array($attribute['type'], ['object', 'array'])) {
                            $track->{$attribute['name']} = isset($node->$key) ? $node->$key : null;
                            if (!is_null($track->{$attribute['name']})) {
                                settype($track->{$attribute['name']}, $attribute['type']);
Severity: Major
Found in src/phpGPX/Parsers/TrackParser.php and 3 other locations - About 1 hr to fix
src/phpGPX/Parsers/MetadataParser.php on lines 87..94
src/phpGPX/Parsers/PointParser.php on lines 121..128
src/phpGPX/Parsers/RouteParser.php on lines 87..94

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

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 4 locations. Consider refactoring.
Open

                default:
                    if (!in_array($attribute['type'], ['object', 'array'])) {
                        $metadata->{$attribute['name']} = isset($node->$key) ? $node->$key : null;
                        if (!is_null($metadata->{$attribute['name']})) {
                            settype($metadata->{$attribute['name']}, $attribute['type']);
Severity: Major
Found in src/phpGPX/Parsers/MetadataParser.php and 3 other locations - About 1 hr to fix
src/phpGPX/Parsers/PointParser.php on lines 121..128
src/phpGPX/Parsers/RouteParser.php on lines 87..94
src/phpGPX/Parsers/TrackParser.php on lines 81..88

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

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 4 locations. Consider refactoring.
Open

                    default:
                        if (!in_array($attribute['type'], ['object', 'array'])) {
                            $route->{$attribute['name']} = isset($node->$key) ? $node->$key : null;
                            if (!is_null($route->{$attribute['name']})) {
                                settype($route->{$attribute['name']}, $attribute['type']);
Severity: Major
Found in src/phpGPX/Parsers/RouteParser.php and 3 other locations - About 1 hr to fix
src/phpGPX/Parsers/MetadataParser.php on lines 87..94
src/phpGPX/Parsers/PointParser.php on lines 121..128
src/phpGPX/Parsers/TrackParser.php on lines 81..88

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

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 4 locations. Consider refactoring.
Open

                default:
                    if (!in_array($attribute['type'], ['object', 'array'])) {
                        $point->{$attribute['name']} = isset($node->$key) ? $node->$key : null;
                        if (!is_null($point->{$attribute['name']})) {
                            settype($point->{$attribute['name']}, $attribute['type']);
Severity: Major
Found in src/phpGPX/Parsers/PointParser.php and 3 other locations - About 1 hr to fix
src/phpGPX/Parsers/MetadataParser.php on lines 87..94
src/phpGPX/Parsers/RouteParser.php on lines 87..94
src/phpGPX/Parsers/TrackParser.php on lines 81..88

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

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

Method toXML has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function toXML(Metadata $metadata, \DOMDocument &$document)
    {
        $node =  $document->createElement(self::$tagName);

        foreach (self::$attributeMapper as $key => $attribute) {
Severity: Minor
Found in src/phpGPX/Parsers/MetadataParser.php - About 1 hr to fix

    The class Stats has 16 fields. Consider redesigning Stats to keep the number of fields under 15.
    Open

    class Stats implements Summarizable
    {
    
        /**
         * Distance in meters (m)
    Severity: Minor
    Found in src/phpGPX/Models/Stats.php by phpmd

    TooManyFields

    Since: 0.1

    Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

    Example

    class Person {
       protected $one;
       private $two;
       private $three;
       [... many more fields ...]
    }

    Source https://phpmd.org/rules/codesize.html#toomanyfields

    The class Point has 24 fields. Consider redesigning Point to keep the number of fields under 15.
    Open

    class Point implements Summarizable
    {
        const WAYPOINT = 'waypoint';
        const TRACKPOINT = 'track';
        const ROUTEPOINT = 'route';
    Severity: Minor
    Found in src/phpGPX/Models/Point.php by phpmd

    TooManyFields

    Since: 0.1

    Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

    Example

    class Person {
       protected $one;
       private $two;
       private $three;
       [... many more fields ...]
    }

    Source https://phpmd.org/rules/codesize.html#toomanyfields

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

        public static function parse(\SimpleXMLElement $node)
        {
            if (!array_key_exists($node->getName(), self::$typeMapper)) {
                return null;
            }
    Severity: Minor
    Found in src/phpGPX/Parsers/PointParser.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

    Method parse has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function parse($nodes)
        {
            $routes = [];
    
            foreach ($nodes as $node) {
    Severity: Minor
    Found in src/phpGPX/Parsers/RouteParser.php - About 1 hr to fix

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

                  if ((phpGPX::$IGNORE_ELEVATION_0 === false || $this->points[$i]->elevation > 0) && $this->stats->minAltitude > $this->points[$i]->elevation) {
                      $this->stats->minAltitude = $this->points[$i]->elevation;
                      $this->stats->minAltitudeCoords = ["lat" => $this->points[$i]->latitude, "lng" => $this->points[$i]->longitude];
                  }
      Severity: Major
      Found in src/phpGPX/Models/Segment.php and 1 other location - About 1 hr to fix
      src/phpGPX/Models/Route.php on lines 114..117

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

      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

                  if ((phpGPX::$IGNORE_ELEVATION_0 === false || $this->points[$p]->elevation > 0) && $this->stats->minAltitude > $this->points[$p]->elevation) {
                      $this->stats->minAltitude = $this->points[$p]->elevation;
                      $this->stats->minAltitudeCoords = ["lat" => $this->points[$p]->latitude, "lng" => $this->points[$p]->longitude];
                  }
      Severity: Major
      Found in src/phpGPX/Models/Route.php and 1 other location - About 1 hr to fix
      src/phpGPX/Models/Segment.php on lines 114..117

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

      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

      Method toXML has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function toXML(Point $point, \DOMDocument &$document)
          {
              $node = $document->createElement(array_search($point->getPointType(), self::$typeMapper));
      
              $node->setAttribute('lat', $point->latitude);
      Severity: Minor
      Found in src/phpGPX/Parsers/PointParser.php - About 1 hr to fix

        Method parse has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function parse(\SimpleXMLElement $node)
            {
                $metadata = new Metadata();
        
                foreach (self::$attributeMapper as $key => $attribute) {
        Severity: Minor
        Found in src/phpGPX/Parsers/MetadataParser.php - About 1 hr to fix

          Function parse has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function parse($nodes)
              {
                  $segments = [];
          
                  foreach ($nodes as $node) {
          Severity: Minor
          Found in src/phpGPX/Parsers/SegmentParser.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

          Method calculate has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function calculate(array $points)
              {
                  $cumulativeElevationGain = 0;
                  $cumulativeElevationLoss = 0;
          
          
          Severity: Minor
          Found in src/phpGPX/Helpers/ElevationGainLossCalculator.php - About 1 hr to fix
            Severity
            Category
            Status
            Source
            Language