EscolaLMS/Courses

View on GitHub

Showing 67 of 67 total issues

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

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

    public function getVideoUrlAttribute(): ?string
    {
        if ($this->attributes['video_path'] ?? null) {
            $path = trim(trim($this->attributes['video_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 355..367
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

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

    public function toArray($request)
    {
        $this->withoutWrapping();

        if ($this->resource instanceof Course) {
Severity: Minor
Found in src/Http/Resources/CourseResource.php - About 1 hr to fix

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

        public function toArray($request): array
        {
            $this->withoutWrapping();
    
            $course = $this->getResource();
    Severity: Minor
    Found in src/Http/Resources/Admin/CourseWithProgramAdminResource.php - About 1 hr to fix

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

          public function run()
          {
              if (Course::count() === 0) {
                  $this->call(CoursesSeeder::class);
              }
      Severity: Minor
      Found in database/seeders/ProgressSeeder.php - About 1 hr to fix

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

            public function toArray($request): array
            {
                $this->withoutWrapping();
        
                $course = $this->getResource();
        Severity: Minor
        Found in src/Http/Resources/CourseWithProgramResource.php - About 1 hr to fix

          Function update has a Cognitive Complexity of 11 (exceeds 5 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

          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 allQueryBuilder has a Cognitive Complexity of 11 (exceeds 5 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

          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 updateInTopic has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function updateInTopic(Topic $topic, Authenticatable $user, int $status, ?int $seconds = null, ?bool $newAttempt = false): void
              {
                  $update = ['status' => $status];
          
                  if (!is_null($seconds)) {
          Severity: Minor
          Found in src/Repositories/CourseProgressRepository.php - About 1 hr to fix

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

                public function run()
                {
                    // create permissions
                    $admin = Role::findOrCreate(UserRole::ADMIN, 'api');
                    $tutor = Role::findOrCreate(UserRole::TUTOR, 'api');
            Severity: Minor
            Found in database/seeders/CoursesPermissionSeeder.php - About 1 hr to fix

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

              <?php
              
              namespace EscolaLms\Courses\Http\Requests;
              
              use Illuminate\Foundation\Http\FormRequest;
              Severity: Major
              Found in src/Http/Requests/DeleteTopicAPIRequest.php and 1 other location - About 1 hr to fix
              src/Http/Requests/DeleteLessonAPIRequest.php on lines 1..37

              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 103.

              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

              <?php
              
              namespace EscolaLms\Courses\Http\Requests;
              
              use EscolaLms\Courses\Models\Lesson;
              Severity: Major
              Found in src/Http/Requests/DeleteLessonAPIRequest.php and 1 other location - About 1 hr to fix
              src/Http/Requests/DeleteTopicAPIRequest.php on lines 1..37

              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 103.

              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

              Function cloneTopic has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function cloneTopic(Topic $topic): Model
                  {
                      $clonedTopicArray = $topic->replicate()->toArray();
                      unset($clonedTopicArray['order']);
                      /** @var Topic $clonedTopic */
              Severity: Minor
              Found in src/Services/TopicService.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

              Function getByUser has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function getByUser(User $user): Collection
                  {
                      $progresses = new Collection();
                      if (!$user instanceof CoursesUser) {
                          /** @var CoursesUser $user */
              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 rules has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function rules(): array
                  {
                      return [
                          'title' => 'string|max:255',
                          'summary' => 'nullable|string',
              Severity: Minor
              Found in src/Models/Course.php - About 1 hr to fix

                Method buildProgress has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function buildProgress(): EloquentCollection
                    {
                        $topicWithProgressId = CourseProgress::where('user_id', $this->user->getKey())->whereIn('topic_id', $this->topics->toArray())->pluck('topic_id')->toArray();
                        $topicsWithoutProgress = $this->course
                            ->topics()
                Severity: Minor
                Found in src/ValueObjects/CourseProgressCollection.php - About 1 hr to fix

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

                      public function toArray($request)
                      {
                          $topicable = $this->resource->topicable;
                  
                          if ($this->resource->lesson && !$this->resource->lesson->isActive()) {
                  Severity: Minor
                  Found in src/Http/Resources/TopicResource.php - About 1 hr to fix

                    Method createTopicContentModelFromRequest has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function createTopicContentModelFromRequest(FormRequest $request, Topic $topic): Model
                        {
                            $class = $request->input('topicable_type');
                    
                            if (!in_array($class, $this->contentClasses)) {
                    Severity: Minor
                    Found in src/Repositories/TopicRepository.php - About 1 hr to fix

                      Function updateInTopic has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function updateInTopic(Topic $topic, Authenticatable $user, int $status, ?int $seconds = null, ?bool $newAttempt = false): void
                          {
                              $update = ['status' => $status];
                      
                              if (!is_null($seconds)) {
                      Severity: Minor
                      Found in src/Repositories/CourseProgressRepository.php - About 55 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 allMain has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                              array $search = [],
                              ?int $skip = null,
                              ?int $limit = null,
                              array $columns = ['*'],
                              string $orderDirection = 'asc',
                      Severity: Minor
                      Found in src/Repositories/Contracts/LessonRepositoryContract.php - About 45 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language