ruby-rdf/rdf

View on GitHub
lib/rdf/vocabulary.rb

Summary

Maintainability
F
1 wk
Test Coverage

File vocabulary.rb has 606 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module RDF
  ##
  # A {Vocabulary} represents an RDFS or OWL vocabulary.
  #
  # A {Vocabulary} can also serve as a Domain Specific Language (DSL) for generating an RDF Graph definition for the vocabulary (see {RDF::Vocabulary#to_enum}).
Severity: Major
Found in lib/rdf/vocabulary.rb - About 1 day to fix

    Method from_graph has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
    Open

          def from_graph(graph, url: nil, class_name: nil, extra: nil)
            vocab = case class_name
            when RDF::Vocabulary
              class_name.instance_variable_set(:@ontology, nil)
              class_name.instance_variable_set(:@properties, nil)
    Severity: Minor
    Found in lib/rdf/vocabulary.rb - About 1 day 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 Vocabulary has 54 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Vocabulary
        extend ::Enumerable
    
        autoload :Format, 'rdf/vocab/writer'
        autoload :Writer, 'rdf/vocab/writer'
    Severity: Major
    Found in lib/rdf/vocabulary.rb - About 7 hrs to fix

      Method attribute_value has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

            def attribute_value(prop)
              values = attributes[prop]
              return nil if values.nil?
              values = [values].compact unless values.is_a?(Array)
              prop_values = values.map do |value|
      Severity: Minor
      Found in lib/rdf/vocabulary.rb - About 6 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 to_ruby has a Cognitive Complexity of 26 (exceeds 5 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 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 from_graph has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def from_graph(graph, url: nil, class_name: nil, extra: nil)
              vocab = case class_name
              when RDF::Vocabulary
                class_name.instance_variable_set(:@ontology, nil)
                class_name.instance_variable_set(:@properties, nil)
      Severity: Major
      Found in lib/rdf/vocabulary.rb - About 3 hrs to fix

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

              def property(*args)
                case args.length
                when 0
                  Term.intern("#{self}property", vocab: self, attributes: {})
                else
        Severity: Minor
        Found in lib/rdf/vocabulary.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 attribute_value has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def attribute_value(prop)
                values = attributes[prop]
                return nil if values.nil?
                values = [values].compact unless values.is_a?(Array)
                prop_values = values.map do |value|
        Severity: Minor
        Found in lib/rdf/vocabulary.rb - About 1 hr to fix

          Method expand_pname has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def expand_pname(pname)
                  return pname unless pname.is_a?(String) || pname.is_a?(Symbol)
                  prefix, suffix = pname.to_s.split(":", 2)
                  # Unescape escaped PN_ESCAPE_CHARS
                  if suffix.match?(RDF::URI::PN_ESCAPES)
          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 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def self.new(*args, vocab: nil, attributes: {}, **options)
                  klass = if args.first.nil?
                    RDF::Node
                  elsif args.first.is_a?(Hash)
                    args.unshift(nil)
          Severity: Minor
          Found in lib/rdf/vocabulary.rb - About 1 hr to fix

            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 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 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 limit_vocabs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                    def limit_vocabs(*vocabs)
                      @vocabs = if Array(vocabs).empty?
                        nil
                      else
                        vocabs.map do |vocab|
              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 a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                    def self.new(*args, vocab: nil, attributes: {}, **options)
                      klass = if args.first.nil?
                        RDF::Node
                      elsif args.first.is_a?(Hash)
                        args.unshift(nil)
              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 register has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                    def register(prefix, vocab, **params)
                      # check the input
                      raise ArgumentError, "#{prefix} must be symbol-able" unless
                        [String, Symbol].any? { |c| prefix.is_a? c }
              
              
              Severity: Minor
              Found in lib/rdf/vocabulary.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 ontology has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def ontology(*args)
                      case args.length
                      when 0
                        @ontology if instance_variable_defined?(:@ontology)
                      else
              Severity: Minor
              Found in lib/rdf/vocabulary.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 find has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def find(uri)
                      uri = RDF::URI(uri) if uri.is_a?(String)
                      return nil unless uri.uri? && uri.valid?
                      RDF::Vocabulary.detect do |v|
                        if uri.length >= v.to_uri.length
              Severity: Minor
              Found in lib/rdf/vocabulary.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

                          attributes[ak] = avs.map do |av|
                            l = RDF::List.new(subject: av, graph: graph)
                            if l.valid?
                              RDF::List.new(subject: av) do |nl|
                                l.each do |lv|
              Severity: Major
              Found in lib/rdf/vocabulary.rb and 1 other location - About 1 hr to fix
              lib/rdf/vocabulary.rb on lines 562..574

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

              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

                          attributes[ak] = avs.is_a?(Array) ? (avs.map do |av|
                            l = RDF::List.new(subject: av, graph: graph)
                            if l.valid?
                              RDF::List.new(subject: av) do |nl|
                                l.each do |lv|
              Severity: Major
              Found in lib/rdf/vocabulary.rb and 1 other location - About 1 hr to fix
              lib/rdf/vocabulary.rb on lines 542..554

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

              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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                    def enum_for(method = :each_statement, *args)
                      # Ensure that enumerators are, themselves, queryable
                      this = self
                      Enumerable::Enumerator.new do |yielder|
                        this.send(method, *args) {|*y| yielder << (y.length > 1 ? y : y.first)}
              Severity: Minor
              Found in lib/rdf/vocabulary.rb and 3 other locations - About 20 mins to fix
              lib/rdf/mixin/enumerable.rb on lines 840..844
              lib/rdf/mixin/queryable.rb on lines 307..311
              lib/rdf/vocabulary.rb on lines 1181..1185

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

              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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                    def enum_for(method = :each_statement, *args)
                      # Ensure that enumerators are, themselves, queryable
                      this = self
                      Enumerable::Enumerator.new do |yielder|
                        this.send(method, *args) {|*y| yielder << (y.length > 1 ? y : y.first)}
              Severity: Minor
              Found in lib/rdf/vocabulary.rb and 3 other locations - About 20 mins to fix
              lib/rdf/mixin/enumerable.rb on lines 840..844
              lib/rdf/mixin/queryable.rb on lines 307..311
              lib/rdf/vocabulary.rb on lines 452..456

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

              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

              There are no issues that match your filters.

              Category
              Status