fluent/fluentd

View on GitHub
lib/fluent/plugin_helper/socket.rb

Summary

Maintainability
D
1 day
Test Coverage

Method socket_create_tls has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

      def socket_create_tls(
          host, port,
          version: Fluent::TLS::DEFAULT_VERSION, min_version: nil, max_version: nil, ciphers: Fluent::TLS::CIPHERS_DEFAULT, insecure: false, verify_fqdn: true, fqdn: nil,
          enable_system_cert_store: true, allow_self_signed_cert: false, cert_paths: nil,
          cert_path: nil, private_key_path: nil, private_key_passphrase: nil,
Severity: Minor
Found in lib/fluent/plugin_helper/socket.rb - About 7 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 socket_create_tls has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def socket_create_tls(
          host, port,
          version: Fluent::TLS::DEFAULT_VERSION, min_version: nil, max_version: nil, ciphers: Fluent::TLS::CIPHERS_DEFAULT, insecure: false, verify_fqdn: true, fqdn: nil,
          enable_system_cert_store: true, allow_self_signed_cert: false, cert_paths: nil,
          cert_path: nil, private_key_path: nil, private_key_passphrase: nil,
Severity: Major
Found in lib/fluent/plugin_helper/socket.rb - About 3 hrs to fix

    Method tls_verify_result_name has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def self.tls_verify_result_name(code)
            case code
            when OpenSSL::X509::V_OK then 'V_OK'
            when OpenSSL::X509::V_ERR_AKID_SKID_MISMATCH then 'V_ERR_AKID_SKID_MISMATCH'
            when OpenSSL::X509::V_ERR_APPLICATION_VERIFICATION then 'V_ERR_APPLICATION_VERIFICATION'
    Severity: Minor
    Found in lib/fluent/plugin_helper/socket.rb - About 1 hr to fix

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

            def socket_create_tcp(host, port, resolve_name: false, connect_timeout: nil, **kwargs, &block)
              sock = if connect_timeout
                       s = ::Socket.tcp(host, port, connect_timeout: connect_timeout)
                       s.autoclose = false # avoid GC triggered close
                       WrappedSocket::TCP.for_fd(s.fileno)
      Severity: Minor
      Found in lib/fluent/plugin_helper/socket.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 socket_create has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

            def socket_create(proto, host, port, **kwargs, &block)
      Severity: Minor
      Found in lib/fluent/plugin_helper/socket.rb - About 35 mins to fix

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

              def socket_create_udp(host, port, resolve_name: false, connect: false, **kwargs, &block)
                family = IPAddr.new(IPSocket.getaddress(host)).ipv4? ? ::Socket::AF_INET : ::Socket::AF_INET6
                sock = WrappedSocket::UDP.new(family)
                socket_option_set(sock, resolve_name: resolve_name, **kwargs)
                sock.connect(host, port) if connect
        Severity: Minor
        Found in lib/fluent/plugin_helper/socket.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

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

              def socket_certificates_from_file(path)
                data = File.read(path)
                pattern = Regexp.compile('-+BEGIN CERTIFICATE-+\r?\n(?:[^-]*\r?\n)+-+END CERTIFICATE-+\r?\n?', Regexp::MULTILINE)
                list = []
                data.scan(pattern) { |match| list << OpenSSL::X509::Certificate.new(match) }
        Severity: Minor
        Found in lib/fluent/plugin_helper/socket.rb and 1 other location - About 35 mins to fix
        lib/fluent/plugin_helper/cert_option.rb on lines 179..187

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

        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