hummingbird-me/kitsu-server

View on GitHub

Showing 165 of 166 total issues

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

  scope :by_kind, ->(*kinds) do
    t = arel_table
    columns = kinds.map { |k| t[:"#{k}_id"] }
    scope = columns.shift.not_eq(nil)
    columns.each do |col|
Severity: Minor
Found in app/models/library_entry.rb and 1 other location - About 35 mins to fix
app/models/library_event.rb on lines 13..21

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

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

  def validate_each(record, attr, value)
    if value.respond_to?(:each)
      value.each do |v|
        error = validate_value(v)
        record.errors.add(attr, message: error) if error
Severity: Minor
Found in app/validators/language_code_validator.rb and 1 other location - About 35 mins to fix
app/validators/country_code_validator.rb on lines 2..10

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

  def followers(sort: [{ on: :created_at, direction: :desc }])
    Loaders::FollowsLoader.connection_for({
      find_by: :followed_id,
      sort: sort
    }, object.id).then do |follows|
Severity: Major
Found in app/graphql/types/profile.rb and 3 other locations - About 35 mins to fix
app/graphql/types/comment.rb on lines 34..39
app/graphql/types/post.rb on lines 65..70
app/graphql/types/profile.rb on lines 103..108

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

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

  def validate_each(record, attr, value)
    if value.respond_to?(:each)
      value.each do |v|
        error = validate_value(v)
        record.errors.add(attr, message: error) if error
Severity: Minor
Found in app/validators/country_code_validator.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 complete_stream_activity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def complete_stream_activity
    stream_activity&.tap do |activity|
      activity.actor ||= user if respond_to?(:user)
      activity.object ||= self
      activity.foreign_id ||= activity.object
Severity: Minor
Found in app/models/concerns/with_activity.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 auto_query_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def auto_query_for(field, value)
    value = value.first if value.is_a?(Array) && value&.count == 1

    case value
    when Range
Severity: Minor
Found in app/services/typesense_search_service.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 sign_in has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def sign_in
        return @signed_in unless @signed_in.nil?

        @agent.get('https://myanimelist.net/login.php') do |login_page|
          # Already logged in!
Severity: Minor
Found in app/services/list_sync/my_anime_list/login.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

  field :wiki_submissions, Types::WikiSubmission.connection_type, null: false do
    description 'Wiki submissions created by this user'
    argument :sort, Loaders::WikiSubmissionsLoader.sort_argument, required: false
    argument :statuses, [Types::Enum::WikiSubmissionStatus],
      required: false,
Severity: Minor
Found in app/graphql/types/profile.rb and 1 other location - About 35 mins to fix
app/graphql/types/profile.rb on lines 140..148

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

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

  def progress_limit
    return unless progress
    progress_cap = media&.progress_limit
    default_cap = [media&.default_progress_limit, 50].compact.max

Severity: Minor
Found in app/models/library_entry.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 ao_importable? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def ao_importable?
      # No Conflict
      return true if kitsu_user.blank?
      # Post-conflict (chose Aozora)
      return false if kitsu_user.ao_imported
Severity: Minor
Found in app/services/zorro/user_conflict_detector.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 fill_defaults has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def fill_defaults(activity)
    activity.tap do |act|
      act.actor ||= user
      act.object ||= library_entry
      act.to ||= []
Severity: Minor
Found in app/services/media_activity_service.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 missing_engagement_ids has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def missing_engagement_ids
    data = @entries.completed.joins(JOINS).group(GROUP).pluck(PLUCK)

    data.each_with_object(
      attributes: [],
Severity: Minor
Found in app/services/library_gaps_service.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 validate_each has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(record, attribute, value)
    ama = if value.respond_to?(:post)
            AMA.for_original_post(value.post).first
          elsif value.is_a?(Post)
            AMA.for_original_post(value).first
Severity: Minor
Found in app/validators/active_ama_validator.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

  field :library_events, Types::LibraryEvent.connection_type, null: false do
    description 'A list of library events for this user'

    argument :sort, Loaders::LibraryEventsLoader.sort_argument, required: false
    argument :kind, [Types::Enum::LibraryEventKind],
Severity: Minor
Found in app/graphql/types/profile.rb and 1 other location - About 35 mins to fix
app/graphql/types/profile.rb on lines 188..195

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

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

    def aozora_user
      return unless ao_importable?

      return @aozora_user if @aozora_user
      return Zorro::DB::User.find(_id: @user.ao_id).first if @user
Severity: Minor
Found in app/services/zorro/user_conflict_detector.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 update? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def update?
    return false unless user
    return false if user.has_role?(:banned)
    return true if can_administrate?
    return false if record.locked?
Severity: Minor
Found in app/policies/post_policy.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 processable has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def processable(column, pipeline)
      processed_column = "processed_#{column}"
      memoized = "@#{processed_column}"

      define_method(processed_column) do
Severity: Minor
Found in app/models/concerns/content_processable.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 update? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def update?
    return false unless user
    return false if user.has_role?(:banned)
    return true if can_administrate?
    # admins are allowed to update comments on locked posts
Severity: Minor
Found in app/policies/comment_policy.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 validate_each has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(record, attr, value)
    if value.respond_to?(:each)
      value.each do |v|
        error = validate_value(v)
        record.errors.add(attr, message: error) if error
Severity: Minor
Found in app/validators/language_code_validator.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 follow has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def follow(source, target)
    return false unless ENV['STREAMLOG_REDIS_URL']
    return unless log_follow?(source, target)
    source = rewrite_feed(*source)
    target = rewrite_feed(*target)
Severity: Minor
Found in lib/stream_log.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

Severity
Category
Status
Source
Language