ruby-rdf/rdf

View on GitHub
lib/rdf/model/literal.rb

Summary

Maintainability
D
1 day
Test Coverage

Class Literal has 33 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Literal

  private
    @@subclasses       = [] # @private
    @@datatype_map     = nil # @private
Severity: Minor
Found in lib/rdf/model/literal.rb - About 4 hrs to fix

    File literal.rb has 282 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'bcp47_spec'
    
    module RDF
      ##
      # An RDF literal.
    Severity: Minor
    Found in lib/rdf/model/literal.rb - About 2 hrs to fix

      Method new has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.new(value, language: nil, datatype: nil, direction: nil, lexical: nil, validate: false, canonicalize: false, **options)
            if language && direction
              raise ArgumentError, "datatype with language and direction must be rdf:dirLangString" if (datatype || RDF.dirLangString).to_s != RDF.dirLangString.to_s
            elsif language
              raise ArgumentError, "datatype with language must be rdf:langString" if (datatype || RDF.langString).to_s != RDF.langString.to_s
      Severity: Minor
      Found in lib/rdf/model/literal.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 valid? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def valid?
            BCP47.parse(language.to_s) if language?
            return false if direction? && !%i{ltr rtl}.include?(direction)
            return false if datatype? && datatype.invalid?
            grammar = self.class.const_get(:GRAMMAR) rescue nil
      Severity: Minor
      Found in lib/rdf/model/literal.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 initialize has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize(value, language: nil, datatype: nil, direction: nil, lexical: nil, validate: false, canonicalize: false, **options)
            @object   = value.freeze
            @string   = lexical if lexical
            @string   = value if !defined?(@string) && value.is_a?(String)
            @string   = @string.encode(Encoding::UTF_8).freeze if instance_variable_defined?(:@string)
      Severity: Minor
      Found in lib/rdf/model/literal.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 new has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.new(value, language: nil, datatype: nil, direction: nil, lexical: nil, validate: false, canonicalize: false, **options)
            if language && direction
              raise ArgumentError, "datatype with language and direction must be rdf:dirLangString" if (datatype || RDF.dirLangString).to_s != RDF.dirLangString.to_s
            elsif language
              raise ArgumentError, "datatype with language must be rdf:langString" if (datatype || RDF.langString).to_s != RDF.langString.to_s
      Severity: Minor
      Found in lib/rdf/model/literal.rb - About 1 hr to fix

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

            def compatible?(other)
              return false unless other.literal? && plain? && other.plain?
        
              # * The arguments are simple literals or literals typed as xsd:string
              # * The arguments are plain literals with identical language-tags
        Severity: Minor
        Found in lib/rdf/model/literal.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 <=> has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def <=>(other)
              case other
              when Literal
                case
                when self.eql?(other)
        Severity: Minor
        Found in lib/rdf/model/literal.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 == has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def ==(other)
              case other
              when Literal
                case
                when self.eql?(other)
        Severity: Minor
        Found in lib/rdf/model/literal.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

        There are no issues that match your filters.

        Category
        Status