ChattyCrow/chattycrow_ruby

View on GitHub

Showing 15 of 15 total issues

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

      def add_file(options = {})
        # Get file
        file = options.delete(:file)

        # Raise argument error when argument file missing!
Severity: Minor
Found in lib/chatty_crow/request/mail.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

      RestClient::Request.execute(options) do |response, request, result, &block|
        begin
          case response.code
          when 200, 201
            Response::Batch.new response, options
Severity: Major
Found in lib/chatty_crow/batch_notification_request.rb and 1 other location - About 1 hr to fix
lib/chatty_crow/notification_request.rb on lines 34..56

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

      RestClient::Request.execute(options) do |response, request, result, &block|
        begin
          case response.code
          when 200, 201
            Response::Notification.new response, options
Severity: Major
Found in lib/chatty_crow/notification_request.rb and 1 other location - About 1 hr to fix
lib/chatty_crow/batch_notification_request.rb on lines 100..122

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

      def initialize(*args)
        # Error when attributes not exists!
        fail ::ArgumentError if args.empty?

        # Parse options and arguments
Severity: Minor
Found in lib/chatty_crow/request.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 proceed has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def proceed(raise_errors = true)
      # Empty requests?
      if requests.empty?
        if raise_errors
          fail ::ArgumentError, 'At least one message is required!'
Severity: Minor
Found in lib/chatty_crow/batch_notification_request.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 proceed has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def proceed(raise_errors = true)
      # Empty requests?
      if requests.empty?
        if raise_errors
          fail ::ArgumentError, 'At least one message is required!'
Severity: Minor
Found in lib/chatty_crow/batch_notification_request.rb - About 1 hr to fix

    Method set_data_from_am has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def set_data_from_am
            # Contacts
            @contacts  = ChattyCrow.wrap(@am_mail.to)
    
            # Channel?
    Severity: Minor
    Found in lib/chatty_crow/request/mail.rb - About 1 hr to fix

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

            def set_data_from_am
              # Contacts
              @contacts  = ChattyCrow.wrap(@am_mail.to)
      
              # Channel?
      Severity: Minor
      Found in lib/chatty_crow/request/mail.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 execute has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.execute(instance, raise_errors = true)
            # Get options
            options = instance.to_json.merge(url: notification_url, method: :post)
      
            # Set options to JSON string
      Severity: Minor
      Found in lib/chatty_crow/notification_request.rb - About 1 hr to fix

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

            def host=(s)
              @host             = s
              @notification_url = s + (s[-1] == '/' ? '' : '/') + 'notification'
              @contacts_url     = s + (s[-1] == '/' ? '' : '/') + 'contacts'
              @messages_url     = s + (s[-1] == '/' ? '' : '/') + 'message'
        Severity: Minor
        Found in lib/chatty_crow/config.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 execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.execute(instance, raise_errors = true)
              # Get options
              options = instance.to_json.merge(url: notification_url, method: :post)
        
              # Set options to JSON string
        Severity: Minor
        Found in lib/chatty_crow/notification_request.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 refresh_data has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def refresh_data(raise_errors = false)
              # Send request
              RestClient::Request.execute(call_options) do |response, request, result, &block|
                begin
                  case response.code
        Severity: Minor
        Found in lib/chatty_crow/message.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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def initialize(response = nil)
                @response = response
                if @response && @response.body
                  @response_body = JSON.parse(@response.body)
                  super(@response_body['msg']) if @response_body['msg']
        Severity: Minor
        Found in lib/chatty_crow/error.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

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

              def file_base64
                f = @file
        
                # ActionDispatch::Http::UploadedFile (get tempfile)
                if defined?(::ActionDispatch) && f.instance_of?(::ActionDispatch::Http::UploadedFile)
        Severity: Minor
        Found in lib/chatty_crow/request/mail.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 execute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.execute(options, &resp_block)
              # Prepare options (url + headers)
              options[:url]     = contacts_url
              options[:headers] = ChattyCrow.default_headers(options.delete(:channel), options.delete(:token))
        
        
        Severity: Minor
        Found in lib/chatty_crow/contacts_request.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