gmailgem/gmail

View on GitHub

Showing 16 of 16 total issues

Class Message has 31 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Message
    PREFETCH_ATTRS = ["UID", "ENVELOPE", "BODY.PEEK[]", "FLAGS", "X-GM-LABELS", "X-GM-MSGID", "X-GM-THRID"].freeze

    # Raised when given label doesn't exists.
    class NoLabelError < RuntimeError; end
Severity: Minor
Found in lib/gmail/message.rb - About 3 hrs to fix

    Consider simplifying this complex logical expression.
    Open

          if args.first.is_a?(Symbol)
            search = MAILBOX_ALIASES[args.shift].dup
            opts = args.first.is_a?(Hash) ? args.first : {}
    
            opts[:after]      and search.concat ['SINCE', Net::IMAP.format_date(opts[:after])]
    Severity: Critical
    Found in lib/gmail/mailbox.rb - About 3 hrs to fix

      Method patch_net_imap_response_parser has 88 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.patch_net_imap_response_parser(klass = Net::IMAP::ResponseParser)
            # https://github.com/ruby/ruby/blob/4d426fc2e03078d583d5d573d4863415c3e3eb8d/lib/net/imap.rb#L2258
            klass.class_eval do
              def msg_att(n = -1)
                match(Net::IMAP::ResponseParser::T_LPAR)
      Severity: Major
      Found in lib/gmail/imap_extensions.rb - About 3 hrs to fix

        Method extract_labels_response has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
        Open

                def extract_labels_response
                  special, quoted = false, false
                  index, paren_count = 0, 0
        
                  # Start parsing response string for the labels section, parentheses inclusive
        Severity: Minor
        Found in lib/gmail/imap_extensions.rb - About 3 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

        Class Base has 23 methods (exceeds 20 allowed). Consider refactoring.
        Open

            class Base
              # Gmail IMAP defaults
              GMAIL_IMAP_HOST = 'imap.gmail.com'.freeze
              GMAIL_IMAP_PORT = 993
        
        
        Severity: Minor
        Found in lib/gmail/client/base.rb - About 2 hrs to fix

          Method wait_once has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              def wait_once(options = {})
                options[:idle_timeout] ||= 29 * 60
          
                response = nil
                loop do
          Severity: Minor
          Found in lib/gmail/mailbox.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 msg_att has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  def msg_att(n = -1)
                    match(Net::IMAP::ResponseParser::T_LPAR)
                    attr = {}
                    while true
                      token = lookahead
          Severity: Minor
          Found in lib/gmail/imap_extensions.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 unescape has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  def unescape
                    unesc = ''
                    special = false
                    escapes = { '\\' => '\\',
                                '"'  => '"',
          Severity: Minor
          Found in lib/gmail/imap_extensions.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 fetch_uids has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def fetch_uids(*args)
                args << :all if args.empty?
          
                if args.first.is_a?(Symbol)
                  search = MAILBOX_ALIASES[args.shift].dup
          Severity: Minor
          Found in lib/gmail/mailbox.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 add_unescape has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def self.add_unescape(klass = String)
                klass.class_eval do
                  # Add a method to string which unescapes special characters
                  # We use a simple state machine to ensure that specials are not
                  # themselves escaped
          Severity: Minor
          Found in lib/gmail/imap_extensions.rb - About 1 hr to fix

            Method fetch_uids has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def fetch_uids(*args)
                  args << :all if args.empty?
            
                  if args.first.is_a?(Symbol)
                    search = MAILBOX_ALIASES[args.shift].dup
            Severity: Minor
            Found in lib/gmail/mailbox.rb - About 1 hr to fix

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

                    def mailbox(name, &block)
                      @mailbox_mutex.synchronize do
                        name = labels.localize(name)
                        mailbox = (mailboxes[name] ||= Mailbox.new(self, name))
                        switch_to_mailbox(mailbox) if @current_mailbox != mailbox
              Severity: Minor
              Found in lib/gmail/client/base.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 x_gm_label_list has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                      def x_gm_label_list
                        if @str.index(/\(([^)]*)\)/ni, @pos)
                          resp = extract_labels_response
              
                          # We need to manually update the position of the regexp to prevent trip-ups
              Severity: Minor
              Found in lib/gmail/imap_extensions.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

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

                    rescue Net::IMAP::NoResponseError => e
                      if raise_errors
                        message = "Couldn't login to given Gmail account: #{username}"
                        message += " (#{e.response.data.text.strip})"
                        raise(AuthorizationError.new(e.response), message, e.backtrace)
              Severity: Minor
              Found in lib/gmail/client/plain.rb and 2 other locations - About 30 mins to fix
              lib/gmail/client/xoauth.rb on lines 26..32
              lib/gmail/client/xoauth2.rb on lines 16..22

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

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

                    rescue Net::IMAP::NoResponseError => e
                      if raise_errors
                        message = "Couldn't login to given Gmail account: #{username}"
                        message += " (#{e.response.data.text.strip})"
                        raise(AuthorizationError.new(e.response), message, e.backtrace)
              Severity: Minor
              Found in lib/gmail/client/xoauth.rb and 2 other locations - About 30 mins to fix
              lib/gmail/client/plain.rb on lines 13..19
              lib/gmail/client/xoauth2.rb on lines 16..22

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

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

                    rescue Net::IMAP::NoResponseError => e
                      if raise_errors
                        message = "Couldn't login to given Gmail account: #{username}"
                        message += " (#{e.response.data.text.strip})"
                        raise(AuthorizationError.new(e.response), message, e.backtrace)
              Severity: Minor
              Found in lib/gmail/client/xoauth2.rb and 2 other locations - About 30 mins to fix
              lib/gmail/client/plain.rb on lines 13..19
              lib/gmail/client/xoauth.rb on lines 26..32

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

              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