pupilfirst/pupilfirst

View on GitHub

Showing 224 of 224 total issues

Avoid too many return statements within this method.
Open

    return true if current_school_admin.present?
Severity: Major
Found in app/policies/timeline_event_file_policy.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

        return false if organisation.blank?
    Severity: Major
    Found in app/policies/timeline_event_policy.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

            return true if course.faculty.exists?(user: current_user)
      Severity: Major
      Found in app/graphql/mutations/create_reaction.rb - About 30 mins to fix

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

              def json_attributes(content_block)
                attributes =
                  content_block
                    .attributes
                    .slice('id', 'block_type', 'content', 'sort_index')
        Severity: Minor
        Found in app/forms/schools/targets/create_content_block_form.rb and 1 other location - About 30 mins to fix
        app/graphql/concerns/content_block_creatable.rb on lines 47..63

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

        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

          def json_attributes(content_block)
            attributes =
              content_block
                .attributes
                .slice('id', 'block_type', 'content', 'sort_index')
        Severity: Minor
        Found in app/graphql/concerns/content_block_creatable.rb and 1 other location - About 30 mins to fix
        app/forms/schools/targets/create_content_block_form.rb on lines 130..146

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

        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

              if form.validate(params)
                level = form.save
                render json: { id: level.id.to_s, number: level.number, error: nil }
              else
                render json: { error: form.errors.full_messages.join(", ") }
        Severity: Minor
        Found in app/controllers/schools/levels_controller.rb and 3 other locations - About 25 mins to fix
        app/controllers/schools/levels_controller.rb on lines 12..17
        app/controllers/schools/target_groups_controller.rb on lines 12..21
        app/controllers/schools/target_groups_controller.rb on lines 32..41

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

        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

              if form.validate(params)
                target_group = form.save
                render json: {
                         id: target_group.id.to_s,
                         sortIndex: target_group.sort_index,
        Severity: Minor
        Found in app/controllers/schools/target_groups_controller.rb and 3 other locations - About 25 mins to fix
        app/controllers/schools/levels_controller.rb on lines 12..17
        app/controllers/schools/levels_controller.rb on lines 23..28
        app/controllers/schools/target_groups_controller.rb on lines 12..21

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

        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

              if form.validate(params)
                level = form.save
                render json: { id: level.id.to_s, number: level.number, error: nil }
              else
                render json: { error: form.errors.full_messages.join(", ") }
        Severity: Minor
        Found in app/controllers/schools/levels_controller.rb and 3 other locations - About 25 mins to fix
        app/controllers/schools/levels_controller.rb on lines 23..28
        app/controllers/schools/target_groups_controller.rb on lines 12..21
        app/controllers/schools/target_groups_controller.rb on lines 32..41

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

        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

          def swap_up(array, element)
            index = array.index(element)
        
            return array if index.zero? || index.blank?
        
        
        Severity: Minor
        Found in app/queries/move_content_block_mutator.rb and 1 other location - About 25 mins to fix
        app/graphql/mutations/move_school_link.rb on lines 66..74

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

        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

            def swap_up(array, element)
              index = array.index(element)
        
              return array if index.zero? || index.blank?
        
        
        Severity: Minor
        Found in app/graphql/mutations/move_school_link.rb and 1 other location - About 25 mins to fix
        app/queries/move_content_block_mutator.rb on lines 26..34

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

        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

              if form.validate(params)
                target_group = form.save
                render json: {
                         id: target_group.id.to_s,
                         sortIndex: target_group.sort_index,
        Severity: Minor
        Found in app/controllers/schools/target_groups_controller.rb and 3 other locations - About 25 mins to fix
        app/controllers/schools/levels_controller.rb on lines 12..17
        app/controllers/schools/levels_controller.rb on lines 23..28
        app/controllers/schools/target_groups_controller.rb on lines 32..41

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

        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

            def resolve(params)
              mutator = CreateTargetVersionMutator.new(context, params)
        
              if mutator.valid?
                mutator.notify(:success, I18n.t("shared.notifications.done"), I18n.t("mutations.create_target_version.new_version_notification"))
        Severity: Minor
        Found in app/graphql/mutations/create_target_version.rb and 1 other location - About 25 mins to fix
        app/graphql/mutations/update_school.rb on lines 10..19

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

        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

          def grade_labels
            grades_and_labels.map do |grades_and_label|
              grade = grades_and_label[:grade]
              label = grades_and_label[:label].strip
              label = label.present? ? label[0..40] : grade.humanize.capitalize
        Severity: Minor
        Found in app/queries/create_evaluation_criterion_mutator.rb and 1 other location - About 25 mins to fix
        app/queries/update_evaluation_criterion_mutator.rb on lines 35..40

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

        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

          def grade_labels
            grades_and_labels.map do |grades_and_label|
              grade = grades_and_label[:grade]
              label = grades_and_label[:label].strip
              label = label.present? ? label[0..40] : grade.humanize.capitalize
        Severity: Minor
        Found in app/queries/update_evaluation_criterion_mutator.rb and 1 other location - About 25 mins to fix
        app/queries/create_evaluation_criterion_mutator.rb on lines 58..63

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

        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

            def resolve(params)
              mutator = UpdateSchoolMutator.new(context, params)
        
              if mutator.valid?
                mutator.notify(:success, I18n.t("shared.notifications.done"), I18n.t("mutations.update_school.details_updated_notification"))
        Severity: Minor
        Found in app/graphql/mutations/update_school.rb and 1 other location - About 25 mins to fix
        app/graphql/mutations/create_target_version.rb on lines 9..18

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

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

            def clone(new_name, school)
              Course.transaction do
                Course
                  .create!(
                    name: new_name,
        Severity: Minor
        Found in app/services/courses/clone_service.rb - 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

        Method curriculum? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def curriculum?
            return true if record.public_preview?
        
            if current_school_admin.present? ||
                 user.course_authors.where(course: record).present?
        Severity: Minor
        Found in app/policies/course_policy.rb - 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

        Method courses has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def courses
              if current_user.blank?
                current_school
                  .courses.with_attached_thumbnail
                  .live
        Severity: Minor
        Found in app/presenters/layouts/app_router_presenter.rb - 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

        Method perform has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def perform(event_type, course, actor, resource)
              webhook_endpoint = course.webhook_endpoint
        
              unless event_type.in?(webhook_endpoint.events)
                raise "#{event_type} was not one of the requested events in WebhookEndpoint##{webhook_endpoint.id}"
        Severity: Minor
        Found in app/jobs/webhook_deliveries/deliver_job.rb - 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

        Method merge_student_profiles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def merge_student_profiles
              return if @old_user.students.blank?
        
              Rails.logger.info("Merging student profiles...")
        
        
        Severity: Minor
        Found in app/services/users/merge_accounts_service.rb - 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