freemanoid/truncator

View on GitHub

Showing 9 of 9 total issues

Method shorten_url has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

      def shorten_url(uri, truncation_length = 42)
        begin
          uri = URI(uri)
        rescue URI::InvalidURIError
          uri = uri.sub(/\Ahttp:\/\//, '') # remove http protocol
Severity: Minor
Found in lib/truncator/url_parser.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

Method shorten_url has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def shorten_url(uri, truncation_length = 42)
        begin
          uri = URI(uri)
        rescue URI::InvalidURIError
          uri = uri.sub(/\Ahttp:\/\//, '') # remove http protocol
Severity: Minor
Found in lib/truncator/url_parser.rb - About 1 hr to fix

    Avoid too many return statements within this method.
    Open

                return uri.special_format.truncate!(truncation_length)
    Severity: Major
    Found in lib/truncator/url_parser.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return uri.to_s.truncate(truncation_length)
      Severity: Major
      Found in lib/truncator/url_parser.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                  return uri.special_format.truncate!(truncation_length)
        Severity: Major
        Found in lib/truncator/url_parser.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                    return uri.special_format.truncate!(truncation_length)
          Severity: Major
          Found in lib/truncator/url_parser.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                          return uri.special_format.truncate!(truncation_length)
            Severity: Major
            Found in lib/truncator/url_parser.rb - About 30 mins to fix

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

                    def truncate!(length, separator = nil)
                      separator ||= self.separator
                      fail ArgumentError, 'Separator should be present. Pass it via last argument or set globally String.separator=' unless separator
                      if self.length > length
                        self[(length - separator.length)..-1] = separator
              Severity: Minor
              Found in lib/truncator/extended_string.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 query_parameters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                    def query_parameters
                      if query_bug_in_ruby?
                        begin
                          URI.decode_www_form(self.query)
                        rescue ArgumentError # fixed in ruby 2.1.0 r40460
              Severity: Minor
              Found in lib/truncator/extended_uri.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