chamilo/chamilo-lms

View on GitHub
src/CoreBundle/Service/CourseService.php

Summary

Maintainability
A
0 mins
Test Coverage

The method __construct has 11 parameters. Consider reducing the number of parameters to less than 10.
Open

    public function __construct(
        private readonly EntityManager $entityManager,
        private readonly CourseRepository $courseRepository,
        private readonly Security $security,
        private readonly CourseCategoryRepository $courseCategoryRepository,

The method registerCourse() has an NPath complexity of 257. The configured NPath complexity threshold is 200.
Open

    public function registerCourse(array $rawParams): ?Course
    {
        try {
            /** @var User $currentUser */
            $currentUser = $this->security->getUser();

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 CourseService has a coupling between objects value of 35. Consider to reduce the number of dependencies under 13.
Open

class CourseService
{
    public const MAX_COURSE_LENGTH_CODE = 40;

    public function __construct(

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 defineCourseKeys uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $keysAreUnique = true;
            }

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 insertExampleContent uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $realPath = str_replace($defaultPath, '', $file->getRealPath());
                $document = DocumentManager::addDocument(
                    $courseInfo,
                    $realPath,

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

Avoid unused local variables such as '$currentUser'.
Open

        $currentUser = $this->security->getUser();

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

Avoid unused parameters such as '$params'.
Open

    public function fillCourse(Course $course, array $params): void

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

Missing function doc comment
Open

    public function createCourse(array $params): ?Course

Missing function doc comment
Open

    public function registerCourse(array $rawParams): ?Course

Variable "app_plugin" is not in valid camel caps format
Open

        $app_plugin = new AppPlugin();

Missing class doc comment
Open

class CourseService

Missing function doc comment
Open

    public function defineCourseKeys(

Add a single space around assignment operators
Open

declare(strict_types=1);

Variable "results_disabled" is not in valid camel caps format
Open

        $exercise->results_disabled = 0;

Variable "app_plugin" is not in valid camel caps format
Open

        $app_plugin->install_course_plugins($courseId);

Missing function doc comment
Open

    public function __construct(

Missing function doc comment
Open

    public function sendEmailToAdmin(Course $course): void

Missing function doc comment
Open

    public function fillCourse(Course $course, array $params): void

Declare public methods first,then protected ones and finally private ones
Open

    public function useTemplateAsBasisIfRequired($courseCode, $courseTemplate): void

Closing brace must be on a line by itself
Open

    ) {}

Missing function doc comment
Open

    public function useTemplateAsBasisIfRequired($courseCode, $courseTemplate): void

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly TranslatorInterface $translator,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly EntityManager $entityManager,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly UserRepository $userRepository,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly MailerInterface $mailer,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly EventLoggerService $eventLoggerService,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly CourseRepository $courseRepository,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly SettingsManager $settingsManager,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly Security $security,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly CourseCategoryRepository $courseCategoryRepository,

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly ParameterBagInterface $parameterBag,

Closing brace must be on a line by itself
Open

    ) {}

Line indented incorrectly; expected 4 spaces, found 8
Open

        private readonly RequestStack $requestStack

The variable $app_plugin is not named in camelCase.
Open

    private function installCoursePlugins(int $courseId): void
    {
        $app_plugin = new AppPlugin();
        $app_plugin->install_course_plugins($courseId);
    }

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $app_plugin is not named in camelCase.
Open

    private function installCoursePlugins(int $courseId): void
    {
        $app_plugin = new AppPlugin();
        $app_plugin->install_course_plugins($courseId);
    }

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

There are no issues that match your filters.

Category
Status