ryanlntn/medic

View on GitHub

Showing 26 of 26 total issues

Method viewDidAppear has 150 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def viewDidAppear(animated)
    if Medic.available?

      types = {
        share: [
Severity: Major
Found in app/controllers/authorize_controller.rb - About 6 hrs to fix

    Method predicate has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def predicate(args={})
          return args if args.is_a? NSPredicate
          if args[:where]
            args[:where]
          elsif args[:predicate]
    Severity: Minor
    Found in lib/medic/predicate.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

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

        def samples_to_hashes(samples)
          samples.map do |sample|
            h = {}
            h[:uuid] = sample.UUID.UUIDString
            h[:metadata] = sample.metadata
    Severity: Minor
    Found in lib/medic/finders.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

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

        NUMBER_WORDS = {
          'zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5,
          'six' => 6, 'seven' => 7, 'eight' => 8, 'nine' => 9, 'ten' => 10, 'eleven' => 11,
          'twelve' => 12, 'thirteen' => 13, 'fourteen' => 14, 'fifteen' => 15, 'sixteen' => 16,
          'seventeen' => 17, 'eighteen' => 18, 'nineteen' => 19, 'twenty' => 20, 'thirty' => 30,
    Severity: Major
    Found in lib/medic/anchor.rb and 1 other location - About 1 hr to fix
    lib/medic/interval.rb on lines 4..10

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

    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

        NUMBER_WORDS = {
          'zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5,
          'six' => 6, 'seven' => 7, 'eight' => 8, 'nine' => 9, 'ten' => 10, 'eleven' => 11,
          'twelve' => 12, 'thirteen' => 13, 'fourteen' => 14, 'fifteen' => 15, 'sixteen' => 16,
          'seventeen' => 17, 'eighteen' => 18, 'nineteen' => 19, 'twenty' => 20, 'thirty' => 30,
    Severity: Major
    Found in lib/medic/interval.rb and 1 other location - About 1 hr to fix
    lib/medic/anchor.rb on lines 4..10

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

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

        def anchor_for_symbol(sym)
          return unless sym
          return sym if sym.to_s == '0'
          return sym if sym.is_a? Fixnum
          return sym if sym.is_a? NSDate
    Severity: Minor
    Found in lib/medic/anchor.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 predicate has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def predicate(args={})
          return args if args.is_a? NSPredicate
          if args[:where]
            args[:where]
          elsif args[:predicate]
    Severity: Minor
    Found in lib/medic/predicate.rb - About 1 hr to fix

      Method samples_to_hashes has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def samples_to_hashes(samples)
            samples.map do |sample|
              h = {}
              h[:uuid] = sample.UUID.UUIDString
              h[:metadata] = sample.metadata
      Severity: Minor
      Found in lib/medic/finders.rb - About 1 hr to fix

        Method statistics_to_hash has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def statistics_to_hash(stats)
              h = {}
              h[:start_date] = stats.startDate
              h[:end_date] = stats.endDate
              h[:sources] = stats.sources.map(&:name) if stats.sources
        Severity: Minor
        Found in lib/medic/finders.rb - 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 get_steps has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def get_steps
            query = Medic::StatisticsCollectionQuery.new(type: :step_count, options: :sum, anchor: one_day_ago, interval: :day)
        
            query.initial_results_handler = ->(query, results, error){
              NSLog("An error occurred calculating statistics: #{error.localizedDescription}") if error
        Severity: Minor
        Found in app/controllers/observer_query_controller.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 prepare_for_save has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def prepare_for_save(sample)
              return sample if sample.kind_of? HKSample
        
              date = sample[:date] || NSDate.date
              start_date = sample[:start] || sample[:start_date] || date
        Severity: Minor
        Found in lib/medic/store.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 viewDidAppear has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def viewDidAppear(animated)
            query_params = { type: :step_count, options: :sum, anchor: one_week_ago, interval: :day }
        
            query = Medic::StatisticsCollectionQuery.new(query_params) do |query, results, error|
              NSLog("An error occurred calculating statistics: #{error.localizedDescription}") if error
        Severity: Minor
        Found in app/controllers/statistics_collection_query_controller.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 interval has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def interval(sym)
              return sym if sym.is_a? NSDateComponents
              parts = sym.to_s.gsub('_', ' ').split
              component = parts.pop.chomp('s')
              n = parts.map{|p| NUMBER_WORDS[p] || p.to_i}.reduce do |sum, p|
        Severity: Minor
        Found in lib/medic/interval.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

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

          class ObserverQueryBuilder
            attr_reader :params
            attr_reader :query
        
            include Medic::Types
        Severity: Minor
        Found in lib/medic/observer_query_builder.rb and 1 other location - About 35 mins to fix
        lib/medic/source_query_builder.rb on lines 2..14

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

        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

          class SourceQueryBuilder
            attr_reader :params
            attr_reader :query
        
            include Medic::Types
        Severity: Minor
        Found in lib/medic/source_query_builder.rb and 1 other location - About 35 mins to fix
        lib/medic/observer_query_builder.rb on lines 2..14

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

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

            def initialize(args={})
              @params = args
              @query = HKStatisticsCollectionQuery.alloc.initWithQuantityType(object_type(args[:type]),
                quantitySamplePredicate: predicate(args),
                options: options_for_stat_query(args[:options]),
        Severity: Minor
        Found in lib/medic/statistics_collection_query_builder.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

            def find_samples(type, options={}, block=Proc.new)
              query_params = options.merge(type: type)
              query = Medic::SampleQueryBuilder.new query_params do |query, results, error|
                block.call(samples_to_hashes(Array(results)))
              end.query
        Severity: Minor
        Found in lib/medic/finders.rb and 1 other location - About 25 mins to fix
        lib/medic/finders.rb on lines 29..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 29.

        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 find_correlations(type, options={}, block=Proc.new)
              query_params = options.merge(type: type)
              query = Medic::CorrelationQueryBuilder.new query_params do |query, correlations, error|
                block.call(samples_to_hashes(Array(correlations)))
              end.query
        Severity: Minor
        Found in lib/medic/finders.rb and 1 other location - About 25 mins to fix
        lib/medic/finders.rb on lines 21..26

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

        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

              n = parts.map{|p| NUMBER_WORDS[p] || p.to_i}.reduce do |sum, p|
                if p == 100 && sum > 0
                  sum * p
                else
                  sum + p
        Severity: Minor
        Found in lib/medic/interval.rb and 1 other location - About 20 mins to fix
        lib/medic/anchor.rb on lines 20..25

        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 initialize(args={}, block=Proc.new)
              @params = args
              @query = HKCorrelationQuery.alloc.initWithType(object_type(args[:type]),
                predicate: predicate(args),
                samplePredicates: sample_predicates(args[:sample_predicates]),
        Severity: Minor
        Found in lib/medic/correlation_query_builder.rb and 1 other location - About 20 mins to fix
        lib/medic/statistics_query_builder.rb on lines 10..16

        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

        Severity
        Category
        Status
        Source
        Language