zhandao/zero-rails

View on GitHub

Showing 11 of 11 total issues

Method open_api_dry has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def open_api_dry
      route_base = try(:controller_path) || oas[:route_base]
      ::OpenApi::Router.get_actions_by_route_base(route_base)&.each do |action|
        api_dry action do
          # Common :index parameters
Severity: Minor
Found in lib/auto_gen_doc.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 open_api_dry has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def open_api_dry
      route_base = try(:controller_path) || oas[:route_base]
      ::OpenApi::Router.get_actions_by_route_base(route_base)&.each do |action|
        api_dry action do
          # Common :index parameters
Severity: Minor
Found in lib/auto_gen_doc.rb - About 1 hr to fix

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

        def register(name, path = nil, format: :normal)
          name = name.to_sym
          path = nil if Rails.env.test? && path&.match?('/data/logs') # for ci
          return puts "Logger named #{name} has exists".red if loggers&.key?(name.to_sym)
    
    
    Severity: Minor
    Found in lib/loggers.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 can? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def can? *permission_codes, source: nil, &block
        block_condition = permission_codes.delete(:then) || permission_codes.delete(:else)
        permission_codes.flatten.each do |code|
          vp = vactual_permissions = [ *Array(MakeSure.permission_mapper[code] || code) ]
          # vp = [ *vp, *PermissionCode.where(code: code).map(&:permissions).flatten.compact.map(&:name).uniq ]
    Severity: Minor
    Found in app/controllers/concerns/make_sure.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 must has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def must *logic_names
        success = nil
        logic_names.each do |logic_name|
          logic = MakeSure.logics.fetch(logic_name)
          result = logic[:lambda] ? @_make_sure_obj.instance_exec(&logic[:lambda]) : instance_eval(&logic[:block])
    Severity: Minor
    Found in app/controllers/concerns/make_sure.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 make_sure has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def make_sure(obj = NoPass, action = nil, *args, &block)
        @_make_sure_obj = obj if obj == :it
        @_make_sure_obj = current_user if obj == NoPass
        return self if action.nil?
    
    
    Severity: Minor
    Found in app/controllers/concerns/make_sure.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

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

        form! data: {
                   :name! => { type: String, permit: true },
            :category_id! => { type: Integer, range: { ge: 1 }, permit: true },
                   :unit! => { type: String, permit: true },
                  :price! => { type: Float, range: { ge: 0 }, permit: true },
    Severity: Minor
    Found in app/_docs/api/v1/goods_doc.rb and 1 other location - About 35 mins to fix
    app/_docs/api/v1/goods_doc.rb on lines 47..53

    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

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

        form! data: {
                   :name => { type: String, permit: true },
            :category_id => { type: Integer, range: { ge: 1 }, permit: true },
                   :unit => { type: String, permit: true },
                  :price => { type: Float, range: { ge: 0 }, permit: true },
    Severity: Minor
    Found in app/_docs/api/v1/goods_doc.rb and 1 other location - About 35 mins to fix
    app/_docs/api/v1/goods_doc.rb on lines 32..38

    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

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

        form! data: {
                             name!: { type: String, permit: true },
                         password!: { type: String, permit: true },
            password_confirmation!: { type: String, permit: true },
                             email: { type: String, permit: true },
    Severity: Minor
    Found in app/_docs/api/v1/users_doc.rb and 1 other location - About 35 mins to fix
    app/_docs/api/v1/users_doc.rb on lines 41..48

    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

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

        form! data: {
                             name: { type: String, permit: true },
                         password: { type: String, permit: true },
            password_confirmation: { type: String, permit: true },
                            email: { type: String, permit: true },
    Severity: Minor
    Found in app/_docs/api/v1/users_doc.rb and 1 other location - About 35 mins to fix
    app/_docs/api/v1/users_doc.rb on lines 30..37

    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

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

        def inherited(subclass)
          super
          subclass.class_eval do
            break unless name.match?(/Controller|Doc/)
            route_base name.sub('Doc', '').underscore.gsub('::', '/') if name.match?(/Doc/)
    Severity: Minor
    Found in lib/auto_gen_doc.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