EscolaLMS/Courses-Import-Export

View on GitHub

Showing 113 of 113 total issues

File ExportImportService.php has 353 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EscolaLms\CoursesImportExport\Services;

use EscolaLms\Categories\Models\Category;
Severity: Minor
Found in src/Services/ExportImportService.php - About 4 hrs to fix

    The class ExportImportService has an overall complexity of 67 which is very high. The configured complexity threshold is 50.
    Open

    class ExportImportService implements ExportImportServiceContract
    {
        private CourseRepositoryContract $courseRepository;
        private LessonRepositoryContract $lessonRepository;
        private TopicRepositoryContract $topicRepository;
    Severity: Minor
    Found in src/Services/ExportImportService.php by phpmd

    ExportImportService has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ExportImportService implements ExportImportServiceContract
    {
        private CourseRepositoryContract $courseRepository;
        private LessonRepositoryContract $lessonRepository;
        private TopicRepositoryContract $topicRepository;
    Severity: Minor
    Found in src/Services/ExportImportService.php - About 2 hrs to fix

      Avoid excessively long class names like EscolaLmsCoursesImportExportServiceProvider. Keep class name length under 40.
      Open

      class EscolaLmsCoursesImportExportServiceProvider extends ServiceProvider
      {
          public $singletons = [
              ExportImportServiceContract::class => ExportImportService::class,
              CloneCourseServiceContract::class => CloneCourseService::class,

      LongClassName

      Since: 2.9

      Detects when classes or interfaces are declared with excessively long names.

      Example

      class ATooLongClassNameThatHintsAtADesignProblem {
      
      }
      
      interface ATooLongInterfaceNameThatHintsAtADesignProblem {
      
      }

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

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

              TopicResourceRepositoryContract $topicResourceRepository,
      Severity: Minor
      Found in src/Services/ExportImportService.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

      Function fixAssetPaths has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function fixAssetPaths(): array
          {
              $results = [];
              $results = $results + $this->fixPath('image_path');
              $results = $results + $this->fixPath('video_path');
      Severity: Minor
      Found in src/Models/Course.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 createTopicFromImport has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function createTopicFromImport(array $topicData, string $dirFullPath, int $courseId): ?Model
          {
              if (!isset($topicData['topicable_type'])) {
                  return null;
              }
      Severity: Minor
      Found in src/Services/ExportImportService.php - About 1 hr to fix

        The parameter $course_id is not named in camelCase.
        Open

            public function clone(int $course_id, CloneCourseAPIRequest $request): JsonResponse
            {
                 $this->cloneCourseService->clone($request->getCourse());
                 return $this->sendSuccess(__('Course cloning started. This may take a while.'));
            }

        CamelCaseParameterName

        Since: 0.2

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

        Example

        class ClassName {
            public function doSomething($user_name) {
            }
        }

        Source

        The parameter $course_id is not named in camelCase.
        Open

            public function export(int $course_id, GetCourseExportAPIRequest $request): JsonResponse;

        CamelCaseParameterName

        Since: 0.2

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

        Example

        class ClassName {
            public function doSomething($user_name) {
            }
        }

        Source

        The parameter $course_id is not named in camelCase.
        Open

            public function clone(int $course_id, CloneCourseAPIRequest $request): JsonResponse;

        CamelCaseParameterName

        Since: 0.2

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

        Example

        class ClassName {
            public function doSomething($user_name) {
            }
        }

        Source

        The parameter $course_id is not named in camelCase.
        Open

            public function export(int $course_id, GetCourseExportAPIRequest $request): JsonResponse
            {
                $export = $this->exportImportService->export($course_id);
        
                return $this->sendResponse($export, __('Export created'));

        CamelCaseParameterName

        Since: 0.2

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

        Example

        class ClassName {
            public function doSomething($user_name) {
            }
        }

        Source

        Function createTopicFromImport has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            private function createTopicFromImport(array $topicData, string $dirFullPath, int $courseId): ?Model
            {
                if (!isset($topicData['topicable_type'])) {
                    return null;
                }
        Severity: Minor
        Found in src/Services/ExportImportService.php - About 45 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 class ExportImportService has a coupling between objects value of 27. Consider to reduce the number of dependencies under 13.
        Open

        class ExportImportService implements ExportImportServiceContract
        {
            private CourseRepositoryContract $courseRepository;
            private LessonRepositoryContract $lessonRepository;
            private TopicRepositoryContract $topicRepository;
        Severity: Minor
        Found in src/Services/ExportImportService.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

        Method __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                CourseRepositoryContract        $courseRepository,
                LessonRepositoryContract        $lessonRepository,
                TopicRepositoryContract         $topicRepository,
                TopicResourceRepositoryContract $topicResourceRepository,
                CategoriesRepositoryContract    $categoriesRepository
        Severity: Minor
        Found in src/Services/ExportImportService.php - About 35 mins to fix

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

              private function createLessonFromImport(array $lessonData, string $dirFullPath): Model
              {
                  $lessonValidator = Validator::make($lessonData, Lesson::$rules);
                  /** @var Lesson $lesson */
                  $lesson = $this->lessonRepository->create($lessonValidator->validate());
          Severity: Minor
          Found in src/Services/ExportImportService.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

          Blank line found at end of control structure
          Open

          
          
          Severity: Minor
          Found in src/Jobs/CloneCourse.php by phpcodesniffer

          The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
          Open

              {

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

              private function createCourseFromImport(array $courseData, string $dirFullPath): Model
              {
                  unset($courseData['author_id']);
          
                  $courseData = $this->addFilesToArrayBasedOnPath($courseData, $dirFullPath);
          Severity: Minor
          Found in src/Services/ExportImportService.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

          Avoid too many return statements within this method.
          Open

                  return false;
          Severity: Major
          Found in src/Policies/CoursesExportPolicy.php - About 30 mins to fix

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

                public function export($courseId, bool $withUrl = true): string;

            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

            Severity
            Category
            Status
            Source
            Language