hamstergem/hamster

View on GitHub
lib/hamster/list.rb

Summary

Maintainability
F
5 days
Test Coverage

File list.rb has 767 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "thread"
require "set"
require "concurrent/atomics"

require "hamster/undefined"
Severity: Major
Found in lib/hamster/list.rb - About 1 day to fix

    Method slice has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def slice(arg, length = (missing_length = true))
          if missing_length
            if arg.is_a?(Range)
              from, to = arg.begin, arg.end
              from += size if from < 0
    Severity: Minor
    Found in lib/hamster/list.rb - About 5 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 _uniq has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def _uniq(items, &block)
          if block_given?
            LazyList.new do
              next self if empty?
              if items.add?(block.call(head))
    Severity: Minor
    Found in lib/hamster/list.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 realize has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def realize
          while true
            # try to "claim" the right to run the block which realizes target
            if @atomic.compare_and_swap(0,1) # full memory barrier here
              begin
    Severity: Minor
    Found in lib/hamster/list.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 indices has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def indices(object = Undefined, i = 0, &block)
          return indices { |item| item == object } if not block_given?
          return EmptyList if empty?
          LazyList.new do
            node = self
    Severity: Minor
    Found in lib/hamster/list.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 select has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def select(&block)
          return enum_for(:select) unless block_given?
          LazyList.new do
            list = self
            while true
    Severity: Minor
    Found in lib/hamster/list.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 eql? has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def eql?(other)
          list = self
          loop do
            return true if other.equal?(list)
            return false unless other.is_a?(List)
    Severity: Minor
    Found in lib/hamster/list.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 slice has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def slice(arg, length = (missing_length = true))
          if missing_length
            if arg.is_a?(Range)
              from, to = arg.begin, arg.end
              from += size if from < 0
    Severity: Minor
    Found in lib/hamster/list.rb - About 1 hr to fix

      Method realize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def realize
              # another thread may get ahead of us and null out @mutex
              mutex = @mutex
              mutex && mutex.synchronize do
                return if @head != Undefined # another thread got ahead of us
      Severity: Minor
      Found in lib/hamster/list.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 realize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def realize
            # another thread may get ahead of us and null out @mutex
            mutex = @mutex
            mutex && mutex.synchronize do
              return if @head != Undefined # another thread got ahead of us
      Severity: Minor
      Found in lib/hamster/list.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 fill has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def fill(obj, index = 0, length = nil)
            if index == 0
              length ||= size
              if length > 0
                LazyList.new do
      Severity: Minor
      Found in lib/hamster/list.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 realize has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def realize
            while true
              # try to "claim" the right to run the block which realizes target
              if @atomic.compare_and_swap(0,1) # full memory barrier here
                begin
      Severity: Minor
      Found in lib/hamster/list.rb - About 1 hr to fix

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

            def delete_at(index)
              if index == 0
                tail
              elsif index < 0
                index += size if index < 0
        Severity: Minor
        Found in lib/hamster/list.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 realize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def realize
                mutex = @mutex
                mutex && mutex.synchronize do
                  return if @head != Undefined
                  @splitter.next_item until @splitter.done?
        Severity: Minor
        Found in lib/hamster/list.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 flat_map has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def flat_map(&block)
              return enum_for(:flat_map) unless block_given?
              LazyList.new do
                next self if empty?
                head_list = List.from_enum(yield(head))
        Severity: Minor
        Found in lib/hamster/list.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 take_while has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def take_while(&block)
              return enum_for(:take_while) unless block_given?
              LazyList.new do
                next self if empty?
                next Cons.new(head, tail.take_while(&block)) if yield(head)
        Severity: Minor
        Found in lib/hamster/list.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

        Avoid too many return statements within this method.
        Open

                  return nil if list.empty?
        Severity: Major
        Found in lib/hamster/list.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return false unless other.head.eql?(list.head)
          Severity: Major
          Found in lib/hamster/list.rb - About 30 mins to fix

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

                def union(other, items = ::Set.new)
                  LazyList.new do
                    next other._uniq(items) if empty?
                    next tail.union(other, items) if items.include?(head)
                    Cons.new(head, tail.union(other, items.add(head)))
            Severity: Minor
            Found in lib/hamster/list.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 insert has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def insert(index, *items)
                  if index == 0
                    return List.from_enum(items).append(self)
                  elsif index > 0
                    LazyList.new do
            Severity: Minor
            Found in lib/hamster/list.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 pop has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def pop
                  LazyList.new do
                    next self if empty?
                    new_size = size - 1
                    next Cons.new(head, tail.take(new_size - 1)) if new_size >= 1
            Severity: Minor
            Found in lib/hamster/list.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 take has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def take(number)
                  LazyList.new do
                    next self if empty?
                    next Cons.new(head, tail.take(number - 1)) if number > 0
                    EmptyList
            Severity: Minor
            Found in lib/hamster/list.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 permutation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def permutation(length = size, &block)
                  return enum_for(:permutation, length) if not block_given?
                  if length == 0
                    yield EmptyList
                  elsif length == 1
            Severity: Minor
            Found in lib/hamster/list.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 flatten has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def flatten
                  LazyList.new do
                    next self if empty?
                    next head.append(tail.flatten) if head.is_a?(List)
                    Cons.new(head, tail.flatten)
            Severity: Minor
            Found in lib/hamster/list.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_by has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def merge_by(&transformer)
                  return merge_by { |item| item } unless block_given?
                  LazyList.new do
                    sorted = reject(&:empty?).sort_by do |list|
                      yield(list.head)
            Severity: Minor
            Found in lib/hamster/list.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

              class Partitioned < Realizable
                def initialize(partitioner, buffer, mutex)
                  super()
                  @partitioner, @buffer, @mutex = partitioner, buffer, mutex
                end
            Severity: Major
            Found in lib/hamster/list.rb and 1 other location - About 2 hrs to fix
            lib/hamster/list.rb on lines 1508..1534

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

            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 Left < Realizable
                  def initialize(splitter, buffer, mutex)
                    super()
                    @splitter, @buffer, @mutex = splitter, buffer, mutex
                  end
            Severity: Major
            Found in lib/hamster/list.rb and 1 other location - About 2 hrs to fix
            lib/hamster/list.rb on lines 1447..1475

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

            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

            There are no issues that match your filters.

            Category
            Status