Dalphi/dalphi

View on GitHub
app/controllers/api/v1/annotation_documents_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

Class has too many lines. [227/100]
Open

    class AnnotationDocumentsController < BaseController
      include Swagger::Blocks
      include ErrorResponse

      before_action :set_annotation_document,

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [18/10]
Open

      def create
        ActionController::Parameters.permit_all_parameters = true
        annotation_documents = []
        annotation_documents_params.each do |ad_params|
          @annotation_document = AnnotationDocument.new(ad_params)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [14/10]
Open

        def annotation_document_params
          return annotation_document_params_from_json if params['_json']
          parameters = params.require(:annotation_document).permit(
            :id,
            :interface_type,

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [11/10]
Open

      def update
        if @annotation_document.update(converted_annotation_document_params)
          render json: @annotation_document.relevant_attributes
        else
          render status: 400,

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Block has too many lines. [32/25]
Open

      swagger_path '/annotation_documents/{id}' do
        operation :patch do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.update.description')
          key :operationId, 'annotation_document_update'

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [32/25]
Open

      swagger_path '/annotation_documents' do
        operation :post do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.create.description')
          key :operationId, 'annotation_document_create'

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [30/25]
Open

        operation :post do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.create.description')
          key :operationId, 'annotation_document_create'
          key :produces, ['application/json']

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Block has too many lines. [30/25]
Open

        operation :patch do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.update.description')
          key :operationId, 'annotation_document_update'
          key :produces, ['application/json']

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

      def create
        ActionController::Parameters.permit_all_parameters = true
        annotation_documents = []
        annotation_documents_params.each do |ad_params|
          @annotation_document = AnnotationDocument.new(ad_params)
Severity: Minor
Found in app/controllers/api/v1/annotation_documents_controller.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

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

      swagger_path '/annotation_documents/{id}' do
        operation :patch do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.update.description')
          key :operationId, 'annotation_document_update'
Severity: Major
Found in app/controllers/api/v1/annotation_documents_controller.rb and 2 other locations - About 2 hrs to fix
app/controllers/api/v1/raw_data_controller.rb on lines 109..143
app/controllers/api/v1/statistics_controller.rb on lines 82..116

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

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 3 locations. Consider refactoring.
Open

      swagger_path '/annotation_documents' do
        operation :post do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.create.description')
          key :operationId, 'annotation_document_create'
Severity: Major
Found in app/controllers/api/v1/annotation_documents_controller.rb and 2 other locations - About 2 hrs to fix
app/controllers/api/v1/raw_data_controller.rb on lines 49..82
app/controllers/api/v1/statistics_controller.rb on lines 44..77

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

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 6 locations. Consider refactoring.
Open

      swagger_path '/annotation_documents/{id}' do
        operation :get do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.show.description')
          key :operationId, 'annotation_document_read'
Severity: Major
Found in app/controllers/api/v1/annotation_documents_controller.rb and 5 other locations - About 1 hr to fix
app/controllers/api/v1/annotation_documents_controller.rb on lines 122..148
app/controllers/api/v1/raw_data_controller.rb on lines 13..39
app/controllers/api/v1/raw_data_controller.rb on lines 167..193
app/controllers/api/v1/statistics_controller.rb on lines 13..39
app/controllers/api/v1/statistics_controller.rb on lines 121..147

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

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 6 locations. Consider refactoring.
Open

      swagger_path '/annotation_documents/{id}' do
        operation :delete do
          key :comsumes, ['application/json']
          key :description, I18n.t('api.annotation_document.destroy.description')
          key :operationId, 'annotation_document_destroy'
Severity: Major
Found in app/controllers/api/v1/annotation_documents_controller.rb and 5 other locations - About 1 hr to fix
app/controllers/api/v1/annotation_documents_controller.rb on lines 14..40
app/controllers/api/v1/raw_data_controller.rb on lines 13..39
app/controllers/api/v1/raw_data_controller.rb on lines 167..193
app/controllers/api/v1/statistics_controller.rb on lines 13..39
app/controllers/api/v1/statistics_controller.rb on lines 121..147

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

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

      def update
        if @annotation_document.update(converted_annotation_document_params)
          render json: @annotation_document.relevant_attributes
        else
          render status: 400,
Severity: Minor
Found in app/controllers/api/v1/annotation_documents_controller.rb and 1 other location - About 25 mins to fix
app/controllers/api/v1/statistics_controller.rb on lines 179..190

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

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

Indent ) the same as the start of the line where ( is.
Open

                                                  )

This cops checks the indentation of hanging closing parentheses in method calls, method definitions, and grouped expressions. A hanging closing parenthesis means ) preceded by a line break.

Example:

# good: when x is on its own line, indent this way
func(
  x,
  y
)

# good: when x follows opening parenthesis, align parentheses
a = b * (x +
         y
        )

# bad
def func(
  x,
  y
  )
end

Indent the first parameter one step more than the start of the previous line.
Open

                                                    name: annotation_document['interface_type']

This cop checks the indentation of the first parameter in a method call. Parameters after the first one are checked by Style/AlignParameters, not by this cop.

Example:

# bad
some_method(
first_param,
second_param)

# good
some_method(
  first_param,
second_param)

Line is too long. [81/80]
Open

            key :description, I18n.t('api.annotation_document.show.response-200')

Line is too long. [84/80]
Open

            key :description, I18n.t('api.annotation_document.destroy.response-200')

Missing top-level class documentation comment.
Open

    class AnnotationDocumentsController < BaseController

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Avoid rescuing without specifying an error class.
Open

        rescue

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Line is too long. [92/80]
Open

        annotation_documents = annotation_documents.first if annotation_documents.count == 1

Inconsistent indentation detected.
Open

        def annotation_document_params_from_json
          JSON.parse(params['_json'])['annotation_document']
        end

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Line is too long. [84/80]
Open

            key :description, I18n.t('api.annotation_document.destroy.response-400')

Line is too long. [99/80]
Open

              converted_params << converted_annotation_document_params(annotation_document).permit!

Inconsistent indentation detected.
Open

        def annotation_document_params
          return annotation_document_params_from_json if params['_json']
          parameters = params.require(:annotation_document).permit(
            :id,
            :interface_type,

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Line is too long. [83/80]
Open

            key :description, I18n.t('api.annotation_document.create.response-200')

Line is too long. [83/80]
Open

            key :description, I18n.t('api.annotation_document.create.response-400')

Use %i or %I for an array of symbols.
Open

                    only: [
                      :show,
                      :update,
                      :destroy
                    ]

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

Inconsistent indentation detected.
Open

        def converted_annotation_document_params(annotation_document = nil)
          annotation_document ||= annotation_document_params
          payload = annotation_document['payload']
          payload.permit! unless payload.class == Hash
          meta = annotation_document['meta']

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Line is too long. [81/80]
Open

          key :description, I18n.t('api.annotation_document.destroy.description')

Line is too long. [95/80]
Open

                                                    name: annotation_document['interface_type']

Avoid rescuing without specifying an error class.
Open

      rescue

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Inconsistent indentation detected.
Open

        def set_annotation_document
          @annotation_document = AnnotationDocument.find(params[:id])
        rescue
          render status: 400,
                 json: {

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Line is too long. [83/80]
Open

            key :description, I18n.t('api.annotation_document.update.response-200')

Line is too long. [83/80]
Open

            key :description, I18n.t('api.annotation_document.update.response-400')

Line is too long. [81/80]
Open

            key :description, I18n.t('api.annotation_document.show.response-400')

Line is too long. [82/80]
Open

          annotation_document['interface_type'] = InterfaceType.find_or_create_by(

Inconsistent indentation detected.
Open

        def annotation_documents_params
          converted_params = []
          params_annotation_documents = params[:annotation_documents]
          if params_annotation_documents.present?
            params_annotation_documents.each do |annotation_document|

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

There are no issues that match your filters.

Category
Status