EscolaLMS/Courses

View on GitHub

Showing 47 of 66 total issues

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

        File CourseRepository.php has 255 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) && 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 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->id,
                          'created_at' => $this->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

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

                    public function allQueryBuilder(array $search = [], array $criteria = []): Builder
                    {
                        /** search main category and all subcategories */
                        if (isset($search) && 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 toArray has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

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

                  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

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

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

                            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

                                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) {
                                            $user = CoursesUser::find($user->getKey());
                                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

                                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']);
                                        $clonedTopic = $this->topicRepository->create($clonedTopicArray);
                                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

                                Severity
                                Category
                                Status
                                Source
                                Language