netglue/prismic-php-kit

View on GitHub
src/Prismic/Document.php

Summary

Maintainability
A
1 hr
Test Coverage
A
100%

Method fromJsonObject has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function fromJsonObject(stdClass $data, Api $api) : DocumentInterface
    {
        $inst        = new static;
        $inst->api   = $api;
        $inst->id    = $inst->assertRequiredProperty($data, 'id', false);
Severity: Minor
Found in src/Prismic/Document.php - About 1 hr to fix

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

    class Document implements DocumentInterface
    {
    
        /** @var string */
        protected $id;
    Severity: Minor
    Found in src/Prismic/Document.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

    The method assertRequiredProperty has a boolean flag argument $nullable, which is a certain sign of a Single Responsibility Principle violation.
    Open

        protected function assertRequiredProperty(stdClass $object, string $property, $nullable = true)
    Severity: Minor
    Found in src/Prismic/Document.php by phpmd

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

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

    Avoid using static access to class '\Prismic\Document\Fragment\FragmentCollection' in method 'fromJsonObject'.
    Open

            $inst->data = FragmentCollection::factory($data, $api->getLinkResolver());
    Severity: Minor
    Found in src/Prismic/Document.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 '\DateTimeImmutable' in method 'fromJsonObject'.
    Open

                $date                 = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $firstPublished);
    Severity: Minor
    Found in src/Prismic/Document.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 '\Prismic\Document\Fragment\Link\DocumentLink' in method 'asLink'.
    Open

            return DocumentLink::withDocument($this, $resolver);
    Severity: Minor
    Found in src/Prismic/Document.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 '\DateTimeImmutable' in method 'fromJsonObject'.
    Open

                $date                = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $lastPublished);
    Severity: Minor
    Found in src/Prismic/Document.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

    @throws annotation of getTranslation has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
    Open

        public function getTranslation(string $lang) :? DocumentInterface
    Severity: Minor
    Found in src/Prismic/Document.php by phan

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

        protected $id;
    Severity: Minor
    Found in src/Prismic/Document.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 $id. Configured minimum length is 3.
    Open

                    $id = isset($language->id) ? (string) $language->id : null;
    Severity: Minor
    Found in src/Prismic/Document.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

    There are no issues that match your filters.

    Category
    Status