EscolaLMS/topic-types

View on GitHub
database/seeders/CoursesWithTopicSeeder.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method run has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run()
    {
        $this->faker = $this->makeFaker();
        $this->faker->addProvider(new FakerProvider($this->faker));
        $randomTags = [
Severity: Major
Found in database/seeders/CoursesWithTopicSeeder.php - About 2 hrs to fix

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

    class CoursesWithTopicSeeder extends Seeder
    {
        use WithFaker;
    
        private function getRandomRichContent(bool $withH5P = false): Factory

    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 getRandomRichContent has a boolean flag argument $withH5P, which is a certain sign of a Single Responsibility Principle violation.
    Open

        private function getRandomRichContent(bool $withH5P = false): Factory

    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 '\EscolaLms\TopicTypes\Models\TopicContent\ScormSco' in method 'getRandomRichContent'.
    Open

                ScormSco::factory(),

    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 '\EscolaLms\HeadlessH5P\Models\H5PContent' in method 'run'.
    Open

                $hasH5P = H5PContent::first() !== null;

    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 '\EscolaLms\TopicTypes\Models\TopicContent\PDF' in method 'getRandomRichContent'.
    Open

                PDF::factory(),

    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 '\EscolaLms\TopicTypes\Models\TopicContent\RichText' in method 'getRandomRichContent'.
    Open

                RichText::factory(),

    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 '\EscolaLms\Tags\Models\Tag' in method 'seedTags'.
    Open

                Tag::create([
                    'morphable_id' => $model->getKey(),
                    'morphable_type' => get_class($model),
                    'title' => $this->faker->randomElement($randomTags),
                ]);

    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 '\EscolaLms\TopicTypes\Models\TopicContent\Video' in method 'getRandomRichContent'.
    Open

                Video::factory(),

    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 '\EscolaLms\TopicTypes\Models\TopicContent\OEmbed' in method 'getRandomRichContent'.
    Open

                OEmbed::factory(),

    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 '\EscolaLms\TopicTypes\Models\TopicContent\H5P' in method 'getRandomRichContent'.
    Open

                $classes[] = H5P::factory();

    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 '\EscolaLms\TopicTypes\Models\TopicContent\Audio' in method 'getRandomRichContent'.
    Open

                Audio::factory(),

    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 '\EscolaLms\TopicTypes\Models\TopicContent\Image' in method 'getRandomRichContent'.
    Open

                Image::factory(),

    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 unused parameters such as '$sequence'.
    Open

                                ->state(new Sequence(fn(Sequence $sequence) => ['title' => 'Lesson ' . $this->faker->word]))

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Expected 0 spaces before closing bracket; newline found
    Open

                            ->has(Lesson::factory()

    Expected 0 spaces before closing bracket; newline found
    Open

                ->has(Lesson::factory()

    Expected 0 spaces before closing bracket; newline found
    Open

                    ->has(Lesson::factory()

    Expected 0 spaces before closing bracket; newline found
    Open

                        ->has(Lesson::factory()

    There are no issues that match your filters.

    Category
    Status