daddyz/phonelib

View on GitHub

Showing 280 of 280 total issues

Method international has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def international(formatted = true, prefix = '+')
      prefix = formatted if formatted.is_a?(String)
      return nil if sanitized.empty?
      return "#{prefix}#{country_prefix_or_not}#{sanitized}" unless possible?
      return "#{prefix}#{data_country_code}#{@national_number}" unless formatted
Severity: Minor
Found in lib/phonelib/phone_formatter.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 load_data has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def load_data
      data_file = "#{File.dirname(__FILE__)}/../../#{FILE_MAIN_DATA}"
      default_data = Marshal.load(File.binread(data_file))
      if override_phone_data
        override_data_file = Marshal.load(File.binread(override_phone_data))
Severity: Minor
Found in lib/phonelib/core.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 ext_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def ext_data
      return @ext_data if defined?(@ext_data) && @ext_data

      result = default_ext_data
      return result unless possible?
Severity: Minor
Found in lib/phonelib/phone_extended_data.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 area_code_possible? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def area_code_possible?
      return false if impossible?

      # has national prefix
      return false unless @data[country][Core::NATIONAL_PREFIX] || country == 'IT'
Severity: Minor
Found in lib/phonelib/phone_formatter.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

Block has too many lines. [30/25]
Open

Gem::Specification.new do |s|
  s.name = 'phonelib'
  s.version = Phonelib::VERSION
  s.authors = ['Vadim Senderovich']
  s.email = ['daddyzgm@gmail.com']
Severity: Minor
Found in phonelib.gemspec by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Method detect_and_parse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def detect_and_parse(phone, country)
      countries_data = country_code_candidates_for(phone).flat_map { |code|
        Phonelib.data_by_country_codes[code] || []
      }
      countries_data.each_with_object({}) do |data, result|
Severity: Minor
Found in lib/phonelib/phone_analyzer.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 separate_extension has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def separate_extension(original)
      return [original, ''] unless Phonelib.extension_separate_symbols

      regex = if Phonelib.extension_separate_symbols.is_a?(Array)
                cr("#{Phonelib.extension_separate_symbols.join('|')}")
Severity: Minor
Found in lib/phonelib/phone.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 national has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def national(formatted = true)
      return @national_number unless possible?
      format_match, format_string = formatting_data

      if format_match
Severity: Minor
Found in lib/phonelib/phone_formatter.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

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

  def phone_types
    method = options[:possible] ? :possible_types : :types
    phone_types = @phone.send(method)
    if (phone_types & [Phonelib::Core::FIXED_OR_MOBILE]).size > 0
      phone_types += [Phonelib::Core::FIXED_LINE, Phonelib::Core::MOBILE]
Severity: Minor
Found in lib/validators/phone_validator3.rb and 1 other location - About 35 mins to fix
lib/validators/phone_validator.rb on lines 104..110

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

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

  def phone_types
    method = options[:possible] ? :possible_types : :types
    phone_types = @phone.send(method)
    if (phone_types & [Phonelib::Core::FIXED_OR_MOBILE]).size > 0
      phone_types += [Phonelib::Core::FIXED_LINE, Phonelib::Core::MOBILE]
Severity: Minor
Found in lib/validators/phone_validator.rb and 1 other location - About 35 mins to fix
lib/validators/phone_validator3.rb on lines 104..110

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

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

  def validate_each(record, attribute, value)
    return if options[:allow_blank] && value.blank?

    @phone = parse(value, specified_country(record))
    valid = phone_valid? && valid_types? && valid_country? && valid_extensions?
Severity: Minor
Found in lib/validators/phone_validator.rb and 1 other location - About 30 mins to fix
lib/validators/phone_validator3.rb on lines 59..65

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

  def validate_each(record, attribute, value)
    return if options[:allow_blank] && value.blank?

    @phone = parse(value, specified_country(record))
    valid = phone_valid? && valid_types? && valid_country? && valid_extensions?
Severity: Minor
Found in lib/validators/phone_validator3.rb and 1 other location - About 30 mins to fix
lib/validators/phone_validator.rb on lines 59..65

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

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

    def raw_national
      return nil if sanitized.nil? || sanitized.empty?
      if valid?
        @national_number
      elsif data_country_code && sanitized.start_with?(data_country_code)
Severity: Minor
Found in lib/phonelib/phone_formatter.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 get_ext_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def get_ext_name(names_key, id_key)
      return nil unless ext_data[id_key]

      res = Phonelib.phone_ext_data[names_key][ext_data[id_key]]
      return nil unless res
Severity: Minor
Found in lib/phonelib/phone_extended_data.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 hash_from_xml has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def hash_from_xml(data, type)
      hash = {}
      case type
      when :attributes
        data.attributes.each do |k, v|
Severity: Minor
Found in lib/phonelib/data_importer_helper.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 fill_possible_to_types_if_nil has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def fill_possible_to_types_if_nil(result)
        result[:types].each do |type, data|
          if data[Core::VALID_PATTERN] && !data[Core::POSSIBLE_PATTERN]
            result[:types][type][Core::POSSIBLE_PATTERN] = case type
                  when Core::GENERAL
Severity: Minor
Found in lib/phonelib/data_importer.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 better_result has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def better_result(base_result, result = nil)
      base_result ||= {}
      return base_result unless result

      return result unless base_result.values.find { |e| e[:possible].any? }
Severity: Minor
Found in lib/phonelib/phone_analyzer.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 country_code has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def country_code
      return @country_code if @country_code

      code = Phonelib.phone_data[country] && Phonelib.phone_data[country][Core::COUNTRY_CODE]
      return @country_code = code unless code == '1' && Phonelib.phone_data[country][Core::LEADING_DIGITS]
Severity: Minor
Found in lib/phonelib/phone_formatter.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 add_additional_regex has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def add_additional_regex(country, type, national_regex)
      return unless Phonelib::Core::TYPES_DESC.keys.include?(type.to_sym)
      return unless national_regex.is_a?(String)
      @@phone_data = @@data_by_country_codes = nil
      @@additional_regexes[country.to_s.upcase] ||= {}
Severity: Minor
Found in lib/phonelib/core.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(phone, country = nil)
      @original, @extension = separate_extension(phone.to_s)
      @extension.gsub!(/[^0-9]/, '') if @extension

      if sanitized.empty?
Severity: Minor
Found in lib/phonelib/phone.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