EscolaLMS/Courses-Import-Export

View on GitHub

Showing 10 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

    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

      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

        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

        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

          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

            Function export has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function export(User $user, Course $course)
                {
                    if ($user->hasRole('admin')) {
                        return true;
                    }
            Severity: Minor
            Found in src/Policies/CoursesExportPolicy.php - About 25 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

            Severity
            Category
            Status
            Source
            Language