EscolaLMS/Courses

View on GitHub

Showing 48 of 67 total issues

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

            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/LessonRepository.php - About 45 mins to fix

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

                  public function updateFromRequest(UpdateTopicAPIRequest $request): Topic
                  {
                      $topic = $request->getTopic()->loadMissing('topicable');
              
                      if ($request->has('topicable_type')) {
              Severity: Minor
              Found in src/Repositories/TopicRepository.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

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

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

                  public function authorize(): bool
                  {
                      $user = auth()->user();
                      $course = Course::find($this->input('course_id'));
                      if (isset($user) && $user->can('update', $course)) {
              Severity: Minor
              Found in src/Http/Requests/SortAPIRequest.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 updateInTopic has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public function updateInTopic(Topic $topic, Authenticatable $user, int $status, ?int $seconds = null, ?bool $newAttempt = false): void
              Severity: Minor
              Found in src/Repositories/CourseProgressRepository.php - About 35 mins to fix

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

                    public function updateInTopic(Topic $topic, Authenticatable $user, int $status, ?int $seconds = null, ?bool $newAttempt = false): void;
                Severity: Minor
                Found in src/Repositories/Contracts/CourseProgressRepositoryContract.php - About 35 mins to fix

                  Function buildProgress has a Cognitive Complexity of 7 (exceeds 5 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 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 getRulesForTopicContentUpdate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function getRulesForTopicContentUpdate(FormRequest $request, TopicContentContract $topicContent)
                      {
                  
                          // we want to do partial update, so we add 'sometimes' to all rules
                          $partialRules = array_map(fn ($field_rules) => is_array($field_rules) ? array_merge(['sometimes'], $field_rules) : 'sometimes' . $field_rules, $topicContent::rules());
                  Severity: Minor
                  Found in src/Repositories/TopicRepository.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 $this->sendResponseForResource(TopicAdminResource::make($topic), __('Topic updated successfully'));
                  Severity: Major
                  Found in src/Http/Controllers/TopicAPIController.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $course->is_published && $course->hasUser($user);
                    Severity: Major
                    Found in src/Policies/CoursesPolicy.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $this->sendSuccess(__('Topic deleted successfully'));
                      Severity: Major
                      Found in src/Http/Controllers/TopicAPIController.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return false;
                        Severity: Major
                        Found in src/Http/Requests/SortAPIRequest.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return $course->hasAuthor($user);
                          Severity: Major
                          Found in src/Policies/CoursesPolicy.php - About 30 mins to fix
                            Severity
                            Category
                            Status
                            Source
                            Language