Sibyx/phpGPX

View on GitHub
src/phpGPX/Models/GpxFile.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

    public function toXML()
    {
        $document = new \DOMDocument("1.0", 'UTF-8');

        $gpx = $document->createElementNS("http://www.topografix.com/GPX/1/1", "gpx");
Severity: Minor
Found in src/phpGPX/Models/GpxFile.php - About 1 hr to fix

    Function toXML has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function toXML()
        {
            $document = new \DOMDocument("1.0", 'UTF-8');
    
            $gpx = $document->createElementNS("http://www.topografix.com/GPX/1/1", "gpx");
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php - About 35 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 toXML() has an NPath complexity of 256. The configured NPath complexity threshold is 200.
    Open

        public function toXML()
        {
            $document = new \DOMDocument("1.0", 'UTF-8');
    
            $gpx = $document->createElementNS("http://www.topografix.com/GPX/1/1", "gpx");
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

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

    The class GpxFile has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
    Open

    class GpxFile implements Summarizable
    {
        /**
         * A list of waypoints.
         * @var Point[]
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    CouplingBetweenObjects

    Since: 1.1.0

    A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

    Example

    class Foo {
        /**
         * @var \foo\bar\X
         */
        private $x = null;
    
        /**
         * @var \foo\bar\Y
         */
        private $y = null;
    
        /**
         * @var \foo\bar\Z
         */
        private $z = null;
    
        public function setFoo(\Foo $foo) {}
        public function setBar(\Bar $bar) {}
        public function setBaz(\Baz $baz) {}
    
        /**
         * @return \SplObjectStorage
         * @throws \OutOfRangeException
         * @throws \InvalidArgumentException
         * @throws \ErrorException
         */
        public function process(\Iterator $it) {}
    
        // ...
    }

    Source https://phpmd.org/rules/design.html#couplingbetweenobjects

    Missing class import via use statement (line '181', column '15').
    Open

                    throw new \RuntimeException("Unsupported file format!");
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '105', column '19').
    Open

            $document = new \DOMDocument("1.0", 'UTF-8');
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Helpers\SerializationHelper' in method 'toArray'.
    Open

                'waypoints' => SerializationHelper::serialize($this->waypoints),
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Helpers\SerializationHelper' in method 'toArray'.
    Open

                'routes' => SerializationHelper::serialize($this->routes),
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Helpers\SerializationHelper' in method 'toArray'.
    Open

                'extensions' => SerializationHelper::serialize($this->extensions)
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Parsers\TrackParser' in method 'toXML'.
    Open

                $gpx->appendChild(TrackParser::toXML($track, $document));
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Parsers\RouteParser' in method 'toXML'.
    Open

                $gpx->appendChild(RouteParser::toXML($route, $document));
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Helpers\SerializationHelper' in method 'toArray'.
    Open

                'tracks' => SerializationHelper::serialize($this->tracks),
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Parsers\MetadataParser' in method 'toXML'.
    Open

                $gpx->appendChild(MetadataParser::toXML($this->metadata, $document));
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Parsers\ExtensionParser' in method 'toXML'.
    Open

                $gpx->appendChild(ExtensionParser::toXML($this->extensions, $document));
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Helpers\SerializationHelper' in method 'toArray'.
    Open

            return SerializationHelper::filterNotNull([
                'creator' => SerializationHelper::stringOrNull($this->creator),
                'metadata' => SerializationHelper::serialize($this->metadata),
                'waypoints' => SerializationHelper::serialize($this->waypoints),
                'routes' => SerializationHelper::serialize($this->routes),
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Helpers\SerializationHelper' in method 'toArray'.
    Open

                'creator' => SerializationHelper::stringOrNull($this->creator),
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\phpGPX' in method 'toXML'.
    Open

            $gpx->setAttribute("creator", $this->creator ? $this->creator : phpGPX::getSignature());
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Helpers\SerializationHelper' in method 'toArray'.
    Open

                'metadata' => SerializationHelper::serialize($this->metadata),
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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 '\phpGPX\Parsers\PointParser' in method 'toXML'.
    Open

                $gpx->appendChild(PointParser::toXML($waypoint, $document));
    Severity: Minor
    Found in src/phpGPX/Models/GpxFile.php by phpmd

    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

    There are no issues that match your filters.

    Category
    Status