inossidabile/protector

View on GitHub

Showing 18 of 18 total issues

Method first_unmodifiable_field has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

        def first_unmodifiable_field(part, fields)
          return (fields.keys.first || '-') unless @access[part]

          diff = fields.keys - @access[part].keys
          return diff.first if diff.length > 0
Severity: Minor
Found in lib/protector/dsl.rb - 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

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

seed do
  500.times do
    d = Dummy.create! string: 'zomgstring', number: [999,777].sample, text: 'zomgtext'

    2.times do
Severity: Major
Found in perf/active_record_perf.rb and 1 other location - About 1 hr to fix
perf/sequel_perf.rb on lines 3..11

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

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

seed do
  500.times do
    d = Dummy.create string: 'zomgstring', number: [999,777].sample, text: 'zomgtext'

    2.times do
Severity: Major
Found in perf/sequel_perf.rb and 1 other location - About 1 hr to fix
perf/active_record_perf.rb on lines 5..13

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

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

        def cannot(action, *fields)
          action = deprecate_actions(action)

          return @destroyable = false if action == :destroy

Severity: Minor
Found in lib/protector/dsl.rb - 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 protector_defend_graph has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def protector_defend_graph(relation, subject)
          return relation unless @opts[:eager_graph]

          @opts[:eager_graph][:reflections].each do |association, reflection|
            model = reflection[:cache][:class] if reflection[:cache].is_a?(Hash) && reflection[:cache][:class]
Severity: Minor
Found in lib/protector/adapters/sequel/dataset.rb - 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 can has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def can(action, *fields)
          action = deprecate_actions(action)

          return @destroyable = true if action == :destroy

Severity: Minor
Found in lib/protector/dsl.rb - 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 initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        def initialize(adapter, model, fields, subject, entry, blocks)
Severity: Minor
Found in lib/protector/dsl.rb - About 45 mins to fix

    Method protector_expand_inclusion_hash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

            def protector_expand_inclusion_hash(inclusion, results=[], base=[], klass=@klass)
              inclusion.each do |key, value|
                model = klass.reflect_on_association(key.to_sym).klass
                value = [value] unless value.is_a?(Array)
                nest  = [key] + base
    Severity: Minor
    Found in lib/protector/adapters/active_record/relation.rb - 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 valid? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

            def valid?(*args)
              if protector_subject?
                state  = Protector.insecurely{ super(*args) }
                method = new_record? ? :first_uncreatable_field : :first_unupdatable_field
                field  = protector_meta.send(method, protector_changed)
    Severity: Minor
    Found in lib/protector/adapters/active_record/validations.rb - 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 k if !x.nil? && x != v
    Severity: Major
    Found in lib/protector/dsl.rb - About 30 mins to fix

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

                def [](name)
                  # rubocop:disable ParenthesesAroundCondition
                  if (
                    !protector_subject? ||
                    name == self.class.primary_key ||
      Severity: Minor
      Found in lib/protector/adapters/active_record/base.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 protector_expand_inclusion has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def protector_expand_inclusion(inclusion, results=[], base=[], klass=@klass)
                if inclusion.is_a?(Hash)
                  protector_expand_inclusion_hash(inclusion, results, base, klass)
                else
                  Array(inclusion).each do |i|
      Severity: Minor
      Found in lib/protector/adapters/active_record/relation.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 exec_queries_with_protector has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def exec_queries_with_protector(*args)
                return @records if loaded?
                return exec_queries_without_protector unless protector_subject?
      
                subject  = protector_subject
      Severity: Minor
      Found in lib/protector/adapters/active_record/relation.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 run_state has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def run_state(state, color)
          data = {}
          prof = @profiling
      
          print_block "Protector #{state.send color}" do
      Severity: Minor
      Found in perf/perf_helpers/boot.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

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

      activate do
        Dummy.instance_eval do
          protect do
            scope { every }
            can :read, :string
      Severity: Minor
      Found in perf/active_record_perf.rb and 1 other location - About 20 mins to fix
      perf/sequel_perf.rb on lines 15..31

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

      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

      activate do
        Dummy.instance_eval do
          protect do
            scope { where }
            can :read, :string
      Severity: Minor
      Found in perf/sequel_perf.rb and 1 other location - About 20 mins to fix
      perf/active_record_perf.rb on lines 17..33

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

      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 create_with_protector!(*args, &block)
                return create_without_protector!(*args, &block) unless protector_subject?
      
                protector_permit_strong_params(args)
      
      
      Severity: Minor
      Found in lib/protector/adapters/active_record/relation.rb and 1 other location - About 15 mins to fix
      lib/protector/adapters/active_record/relation.rb on lines 103..110

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

      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 create_with_protector(*args, &block)
                return create_without_protector(*args, &block) unless protector_subject?
      
                protector_permit_strong_params(args)
      
      
      Severity: Minor
      Found in lib/protector/adapters/active_record/relation.rb and 1 other location - About 15 mins to fix
      lib/protector/adapters/active_record/relation.rb on lines 114..121

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

      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

      Severity
      Category
      Status
      Source
      Language