gitcoinco/code_fund_ads

View on GitHub

Showing 211 of 211 total issues

Avoid too many return statements within this function.
Open

    return true
Severity: Major
Found in app/javascript/controllers/application_controller.js - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

        return unless impression.creative
    Severity: Major
    Found in app/jobs/create_click_job.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

          return if property.prohibit_fallback_campaigns?
      Severity: Major
      Found in app/controllers/advertisements_controller.rb - About 30 mins to fix

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

          scope :order_by_status, -> {
                                    order_by = ["CASE"]
                                    ENUMS::CAMPAIGN_STATUSES.values.each_with_index do |status, index|
                                      order_by << "WHEN status='#{status}' THEN #{index}"
                                    end
        Severity: Minor
        Found in app/models/campaign.rb and 2 other locations - About 25 mins to fix
        app/models/creative.rb on lines 68..75
        app/models/property.rb on lines 116..123

        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 displayed_campaigns(start_date = nil, end_date = nil)
            subquery = daily_summaries.displayed.where(scoped_by_type: "Campaign")
            subquery = subquery.between(start_date, end_date) if start_date
            Campaign.where id: subquery.distinct.pluck(:scoped_by_id).map(&:to_i)
          end
        Severity: Minor
        Found in app/models/property.rb and 1 other location - About 25 mins to fix
        app/models/campaign.rb on lines 418..422

        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 displaying_properties(start_date = nil, end_date = nil)
            subquery = daily_summaries.displayed.where(scoped_by_type: "Property")
            subquery = subquery.between(start_date, end_date) if start_date
            Property.where id: subquery.distinct.pluck(:scoped_by_id).map(&:to_i)
          end
        Severity: Minor
        Found in app/models/campaign.rb and 1 other location - About 25 mins to fix
        app/models/property.rb on lines 232..236

        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 3 locations. Consider refactoring.
        Open

          scope :order_by_status, -> {
                                    order_by = ["CASE"]
                                    ENUMS::PROPERTY_STATUSES.values.each_with_index do |status, index|
                                      order_by << "WHEN status='#{status}' THEN #{index}"
                                    end
        Severity: Minor
        Found in app/models/property.rb and 2 other locations - About 25 mins to fix
        app/models/campaign.rb on lines 192..199
        app/models/creative.rb on lines 68..75

        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 3 locations. Consider refactoring.
        Open

          scope :order_by_status, -> {
                                    order_by = ["CASE"]
                                    ENUMS::CREATIVE_STATUSES.values.each_with_index do |status, index|
                                      order_by << "WHEN status='#{status}' THEN #{index}"
                                    end
        Severity: Minor
        Found in app/models/creative.rb and 2 other locations - About 25 mins to fix
        app/models/campaign.rb on lines 192..199
        app/models/property.rb on lines 116..123

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

          def daily_impressions_counts(start_date = nil, end_date = nil, scoped_by: nil, fresh: false)
            start_date = Date.coerce(start_date)
            end_date = Date.coerce(end_date || start_date)
            key = "#{cache_key}/#{__method__}/#{start_date.iso8601}-#{end_date.iso8601}/#{scoped_by&.cache_key}"
            fetch_from_cache key, force: fresh do
        Severity: Minor
        Found in app/models/concerns/impressionable.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 old_attached_table_names has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def old_attached_table_names(months_retained: MIN_MONTHS_RETAINED)
                months_retained = MIN_MONTHS_RETAINED if months_retained < MIN_MONTHS_RETAINED
                attached_table_names.select do |attached_table_name|
                  _, year, month, _, _ = attached_table_name.split("_")
                  next unless year && month
        Severity: Minor
        Found in app/models/concerns/impressions/partitionable.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 ecpm has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def ecpm(base: nil, multiplier: nil)
            base = Money.new(ENV.fetch("BASE_ECPM", 400).to_i, "USD") unless base.is_a?(Money)
            value = base * (subregion_cpm_multiplier || Country::UNKNOWN_CPM_MULTIPLER)
            value = base * (country_cpm_multiplier || Country::UNKNOWN_CPM_MULTIPLER) if multiplier.to_s == "country"
            value = Monetize.parse("$0.10 USD") if value.cents < 10
        Severity: Minor
        Found in app/models/country.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

        Function updateProvinceCodeOptions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          updateProvinceCodeOptions (event) {
            if (event && event.type === 'keyup' && event.key !== 'Enter') return
            if (
              event &&
              event.type === 'cf:select:changed' &&
        Severity: Minor
        Found in app/javascript/controllers/select_geo_targets_controller.js - 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

        Function visible has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          get visible () {
            let currentElement = this.container
            if (!currentElement) return false
            while (currentElement) {
              const style = getComputedStyle(currentElement)
        Severity: Minor
        Found in app/javascript/advertisements/index.js - 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(sgid, body, tags = [])
            ScoutApm::Transaction.ignore! if rand > (ENV["SCOUT_SAMPLE_RATE"] || 1).to_f
            eventable = GlobalID::Locator.locate_signed(sgid)
            return unless eventable
            event = Event.build_from(eventable, body, tags)
        Severity: Minor
        Found in app/jobs/create_event_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 validate_request has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def validate_request
            head :bad_request unless EmailAddress.valid?(campaign_report_params[:email])
            head :bad_request unless @campaign
            head :bad_request unless @campaign.summary(@start_date, @end_date)
          end
        Severity: Minor
        Found in app/controllers/campaign_reports_controller.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 update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def update
            return render_forbidden unless authorized_user.can_update_job_posting?(@job_posting, session.id)
            respond_to do |format|
              if @job_posting.update(job_posting_params)
                session[:job_posting_prospect_id] ||= @job_posting.id
        Severity: Minor
        Found in app/controllers/job_posting_prospects_controller.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
            ScoutApm::Transaction.ignore! if rand > (ENV["SCOUT_SAMPLE_RATE"] || 1).to_f
            Campaign.active.find_each do |campaign|
              next unless campaign.end_date.past?
              campaign.update status: ENUMS::CAMPAIGN_STATUSES::ARCHIVED
        Severity: Minor
        Found in app/jobs/update_campaign_statuses_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 job_posting_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def job_posting_params
            params.require(:job_posting).permit(
              :auto_renew,
              :company_name,
              :company_url,
        Severity: Minor
        Found in app/controllers/job_postings_controller.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 prepare_row_for_download has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def prepare_row_for_download(row)
              row.map do |value|
                case value
                when Money then value > 0 ? value.to_f : nil
                else value
        Severity: Minor
        Found in app/models/concerns/campaigns/reportable.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def initialize(attrs = {})
            super FIELDS, attrs
            (self.ad_templates ||= []).reject!(&:blank?)
            (self.keywords ||= []).reject!(&:blank?)
            (self.negative_keywords ||= []).reject!(&:blank?)
        Severity: Minor
        Found in app/models/property_search.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