ruby-rdf/rdf

View on GitHub

Showing 188 of 213 total issues

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

    def self.open_file(filename_or_url, proxy: nil, headers: {}, verify_none: false, **options, &block)
      filename_or_url = $1 if filename_or_url.to_s.match(/^file:(.*)$/)
      remote_document = nil

      if filename_or_url.to_s.match?(/^https?/)
Severity: Minor
Found in lib/rdf/util/file.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 read_triple has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def read_triple
      loop do
        readline.strip! # EOFError thrown on end of input
        line = @line    # for backtracking input in case of parse error

Severity: Minor
Found in lib/rdf/ntriples/reader.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 each_statement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def each_statement
        attributes.keys.each do |p|
          prop = ATTR_URIs.fetch(p) { RDF::Vocabulary::expand_pname(p)}
          values = attribute_value(p)
          values = [values].compact unless values.is_a?(Array)
Severity: Minor
Found in lib/rdf/vocabulary.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 each has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def each(&block)
        if self.equal?(Vocabulary)
          if instance_variable_defined?(:@vocabs) && @vocabs
            @vocabs.select(&:name).each(&block)
          else
Severity: Minor
Found in lib/rdf/vocabulary.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 to_ruby has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def to_ruby(indent: "")
            "term(" +
            (self.uri? ? self.to_s.inspect + ",\n" : "\n") +
            "#{indent}  " +
            attributes.keys.sort.map do |k|
    Severity: Minor
    Found in lib/rdf/vocabulary.rb - About 1 hr to fix

      Method write_statement has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def write_statement(statement)
            statement = statement.canonicalize! if canonicalize?
      
            # Make sure BNodes in statement use unique identifiers
            if statement.node?
      Severity: Minor
      Found in lib/rdf/writer.rb - About 1 hr to fix

        Method escape has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.escape(string, encoding = nil)
              ret = case
                when string.match?(ESCAPE_PLAIN) # a shortcut for the simple case
                  string
                when string.ascii_only?
        Severity: Minor
        Found in lib/rdf/ntriples/writer.rb - About 1 hr to fix

          Method content_type has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def self.content_type(type = nil, options = {})
                if type.nil?
                  [@@content_type[self], @@content_types.map {
                    |ct, cl| (cl.include?(self) && ct != @@content_type[self]) ?  ct : nil }].flatten.compact
                else
          Severity: Minor
          Found in lib/rdf/format.rb - About 1 hr to fix

            Method initialize has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def initialize(body, options = {})
                    options.each do |key, value|
                      # de-quote charset
                      matchdata = value.match(/^["'](.*)["']$/.freeze) if key == "charset"
                      value = matchdata[1] if matchdata
            Severity: Minor
            Found in lib/rdf/util/file.rb - About 1 hr to fix

              Method open has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def self.open(filename, format: nil, **options, &block)
                    # If we're the abstract reader, and we can figure out a concrete reader from format, use that.
                    if self == RDF::Reader && format && reader = self.for(format)
                      return reader.open(filename, format: format, **options, &block)
                    end
              Severity: Minor
              Found in lib/rdf/reader.rb - About 1 hr to fix

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

                    def initialize!
                      @graph_name   = Node.intern(@graph_name)   if @graph_name.is_a?(Symbol)
                      @subject   = if @subject.is_a?(Value)
                        @subject.to_term
                      elsif @subject.is_a?(Symbol)
                Severity: Minor
                Found in lib/rdf/model/statement.rb - About 1 hr to fix

                  Method []= has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def []=(*args)
                        start, length = 0, 0
                  
                        ary = self.to_a
                  
                  
                  Severity: Minor
                  Found in lib/rdf/model/list.rb - About 1 hr to fix

                    Method normalized_path has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def normalized_path
                          if normalized_scheme == "urn"
                            # Special-case URI. Normalize the NID component only
                            nid, p = path.to_s.split(':', 2)
                            return "#{nid.downcase}:#{p}"
                    Severity: Minor
                    Found in lib/rdf/model/uri.rb - About 1 hr to fix

                      Method commands has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def self.commands(format: nil, **options)
                            # First, load commands from other formats
                            load_commands
                      
                            case format
                      Severity: Minor
                      Found in lib/rdf/cli.rb - About 1 hr to fix

                        Method / has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            def /(fragment)
                              frag = fragment.respond_to?(:to_uri) ? fragment.to_uri : RDF::URI(fragment.to_s)
                              raise ArgumentError, "Non-absolute URI or string required, got #{frag}" unless frag.relative?
                              if urn?
                                RDF::URI.intern(to_s.sub(/:+$/,'') + ':' + fragment.to_s.sub(/^:+/,''))
                        Severity: Minor
                        Found in lib/rdf/model/uri.rb - About 1 hr to fix

                          Method serialize_value has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                                def serialize_value(value, key, indent: "")
                                  if value.is_a?(Hash)
                                    # Favor English
                                    keys = value.keys
                                    keys = keys.include?(:en) ? (keys - [:en]).sort.unshift(:en) : keys.sort
                          Severity: Minor
                          Found in lib/rdf/vocab/writer.rb - About 1 hr to fix

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

                                def initialize(name = nil, value = nil, distinguished: nil, existential: nil)
                                  name = (name || "g#{__id__.to_i.abs}").to_s
                                  if name.start_with?('??')
                                    name, dis, ex = name[2..-1], false, false
                                  elsif name.start_with?('?')
                            Severity: Minor
                            Found in lib/rdf/query/variable.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 for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def self.for(*arg, &block)
                                  case arg.length
                                  when 0 then arg = nil
                                  when 1 then arg = arg.first
                                  else
                            Severity: Minor
                            Found in lib/rdf/format.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

                            Severity
                            Category
                            Status
                            Source
                            Language