EscolaLMS/Courses

View on GitHub

Showing 67 of 67 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        return [
            'id' => $this->resource->id,
            'title' => $this->resource->title,
            'lesson_id' => $this->resource->lesson_id,
            'active' => $this->resource->active,
Severity: Major
Found in src/Http/Resources/Admin/TopicAdminResource.php and 1 other location - About 3 hrs to fix
src/Http/Resources/TopicResource.php on lines 29..46

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 151.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        return [
            'id' => $this->resource->id,
            'title' => $this->resource->title,
            'lesson_id' => $this->resource->lesson_id,
            'active' => $this->resource->active,
Severity: Major
Found in src/Http/Resources/TopicResource.php and 1 other location - About 3 hrs to fix
src/Http/Resources/Admin/TopicAdminResource.php on lines 28..45

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 151.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Course has 25 functions (exceeds 20 allowed). Consider refactoring.
Open

class Course extends Model
{
    use HasFactory;
    use QueryCacheable;

Severity: Minor
Found in src/Models/Course.php - About 2 hrs to fix

    File Course.php has 275 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace EscolaLms\Courses\Models;
    
    use EscolaLms\Categories\Models\Category;
    Severity: Minor
    Found in src/Models/Course.php - About 2 hrs to fix

      Function run has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function run()
          {
              if (Course::count() === 0) {
                  $this->call(CoursesSeeder::class);
              }
      Severity: Minor
      Found in database/seeders/ProgressSeeder.php - About 2 hrs 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

      CourseProgressCollection has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class CourseProgressCollection extends ValueObject implements ValueObjectContract, CourseProgressCollectionContract
      {
          public const FORGET_TRACKING_SESSION_AFTER_MINUTES = 60;
      
          private CourseProgressRepositoryContract $courseProgressRepositoryContract;
      Severity: Minor
      Found in src/ValueObjects/CourseProgressCollection.php - About 2 hrs to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function assign(AssignAuthorApiRequest $request): JsonResponse
            {
                $tutor = $request->getTutor();
                $course = $request->getCourse();
        
        
        Severity: Major
        Found in src/Http/Controllers/CourseAuthorsAPIController.php and 1 other location - About 2 hrs to fix
        src/Http/Controllers/CourseAuthorsAPIController.php on lines 68..83

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 131.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function unassign(AssignAuthorApiRequest $request): JsonResponse
            {
                $tutor = $request->getTutor();
                $course = $request->getCourse();
        
        
        Severity: Major
        Found in src/Http/Controllers/CourseAuthorsAPIController.php and 1 other location - About 2 hrs to fix
        src/Http/Controllers/CourseAuthorsAPIController.php on lines 51..66

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 131.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        File CourseRepository.php has 265 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        <?php
        
        namespace EscolaLms\Courses\Repositories;
        
        use EscolaLms\Categories\Models\Category;
        Severity: Minor
        Found in src/Repositories/CourseRepository.php - About 2 hrs to fix

          Method allQueryBuilder has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function allQueryBuilder(array $search = [], array $criteria = []): Builder
              {
                  /** search main category and all subcategories */
                  if (isset($search['category_id'])) {
                      $collection = Category::where('id', $search['category_id'])->with('children')->get();
          Severity: Minor
          Found in src/Repositories/CourseRepository.php - About 1 hr to fix

            Method update has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function update(array $input, int $id): Model
                {
                    $query = $this->model->newQuery();
            
                    /** @var Course $model */
            Severity: Minor
            Found in src/Repositories/CourseRepository.php - About 1 hr to fix

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

              <?php
              
              namespace EscolaLms\Courses\Http\Requests;
              
              use EscolaLms\Courses\Models\Lesson;
              Severity: Major
              Found in src/Http/Requests/GetLessonAPIRequest.php and 3 other locations - About 1 hr to fix
              src/Http/Requests/CloneLessonAPIRequest.php on lines 1..31
              src/Http/Requests/CloneTopicAPIRequest.php on lines 1..31
              src/Http/Requests/GetTopicAPIRequest.php on lines 1..39

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 111.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

              <?php
              
              namespace EscolaLms\Courses\Http\Requests;
              
              use EscolaLms\Courses\Models\Lesson;
              Severity: Major
              Found in src/Http/Requests/CloneLessonAPIRequest.php and 3 other locations - About 1 hr to fix
              src/Http/Requests/CloneTopicAPIRequest.php on lines 1..31
              src/Http/Requests/GetLessonAPIRequest.php on lines 1..39
              src/Http/Requests/GetTopicAPIRequest.php on lines 1..39

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 111.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

              <?php
              
              namespace EscolaLms\Courses\Http\Requests;
              
              use EscolaLms\Courses\Models\Topic;
              Severity: Major
              Found in src/Http/Requests/GetTopicAPIRequest.php and 3 other locations - About 1 hr to fix
              src/Http/Requests/CloneLessonAPIRequest.php on lines 1..31
              src/Http/Requests/CloneTopicAPIRequest.php on lines 1..31
              src/Http/Requests/GetLessonAPIRequest.php on lines 1..39

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 111.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

              <?php
              
              namespace EscolaLms\Courses\Http\Requests;
              
              use EscolaLms\Courses\Models\Topic;
              Severity: Major
              Found in src/Http/Requests/CloneTopicAPIRequest.php and 3 other locations - About 1 hr to fix
              src/Http/Requests/CloneLessonAPIRequest.php on lines 1..31
              src/Http/Requests/GetLessonAPIRequest.php on lines 1..39
              src/Http/Requests/GetTopicAPIRequest.php on lines 1..39

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 111.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Method getCoursesListWithOrdering has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getCoursesListWithOrdering(OrderDto $orderDto, array $search = []): Builder
                  {
                      $criteria = $this->prepareCriteria($orderDto);
              
                      if (isset($search['title'])) {
              Severity: Minor
              Found in src/Services/CourseService.php - About 1 hr to fix

                Method toArray has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function toArray($request)
                    {
                        $fields = [
                            'id' => $this->resource->id,
                            'created_at' => $this->resource->created_at,
                Severity: Minor
                Found in src/Http/Resources/CourseSimpleResource.php - About 1 hr to fix

                  Function update has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function update(Course $course, User $user, array $progress): CourseProgressCollection
                      {
                          $courseProgressCollection = CourseProgressCollection::make($user, $course);
                  
                          if ($courseProgressCollection->courseCanBeProgressed()) {
                  Severity: Minor
                  Found in src/Services/ProgressService.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 toArray has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function toArray($request)
                      {
                          $fields = [
                              'id' => $this->resource->id,
                              'created_at' => $this->resource->created_at,
                  Severity: Minor
                  Found in src/Http/Resources/CourseListResource.php - About 1 hr to fix

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                        public function getImageUrlAttribute(): ?string
                        {
                            if ($this->attributes['image_path'] ?? null) {
                                $path = trim(trim($this->attributes['image_path'], '/'));
                                if ($path) {
                    Severity: Major
                    Found in src/Models/Course.php and 2 other locations - About 1 hr to fix
                    src/Models/Course.php on lines 369..381
                    src/Models/Course.php on lines 383..395

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 108.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Severity
                    Category
                    Status
                    Source
                    Language