Showing 257 of 257 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
module Jobs
module Media
# Cuts audio files and generates spectrograms.
class SpectrogramJob < MediaJob
queue_as Settings.actions.media.queue
- Read upRead up
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 103.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
module Jobs
module Media
# Cuts audio files and generates spectrograms.
class AudioJob < MediaJob
queue_as Settings.actions.media.queue
- Read upRead up
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 103.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Class AudioBase
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class AudioBase
attr_reader :audio_defaults, :logger, :temp_dir, :timeout_sec,
:audio_ffmpeg, :audio_mp3splt, :audio_sox,
:audio_wavpack, :audio_shntool, :audio_waveform,
:audio_wac2wav
Method check_request_parameters
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
def check_request_parameters(audio_recording, request_params)
original_duration = audio_recording.duration_seconds
# offsets
start_offset = nil
Method show_results
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def show_results(is_head_request, analysis_job_item, results_path, api_opts)
# assertion: audio_recordings must be in the specified job - authorization should filter out those that aren't
# extract parameters for analysis response
audio_recording = analysis_job_item.audio_recording
- Read upRead up
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 create
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def create
#do_new_resource - custom new audio_recording
#do_set_attributes(audio_recording_params) - custom set attributes
@audio_recording = AudioRecording.build_by_file_hash(audio_recording_params)
get_project_site
- Read upRead up
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
File audio_event.rb
has 280 lines of code (exceeds 250 allowed). Consider refactoring. Open
class AudioEvent < ApplicationRecord
# relations
belongs_to :audio_recording, inverse_of: :audio_events
belongs_to :audio_event_import, inverse_of: :audio_events, optional: true
has_many :taggings, inverse_of: :audio_event, strict_loading: false
Method download
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
def download
params_cleaned = CleanParams.perform(audio_event_download_params)
is_authorized = false
Method filter_settings
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.filter_settings(is_system = false)
fields = [
:id, :analysis_job_id, :audio_recording_id,
:created_at, :queued_at, :work_started_at, :completed_at,
:queue_id,
Method filter_settings
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.filter_settings
{
valid_fields: [:id, :audio_recording_id,
:start_time_seconds, :end_time_seconds,
:low_frequency_hertz, :high_frequency_hertz,
Method annotation_download
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def annotation_download
selected_params = annotation_download_params
selected_project_id = selected_params[:selected_project_id]
selected_site_id = selected_params[:selected_site_id]
- Read upRead up
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
File validate.rb
has 272 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'active_support/concern'
# Provides common validations for composing queries.
module Filter
module Validate
File schema.rb
has 270 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Api
# The OpenAPI schema for the API.
module Schema
extend Helpers
File media_metadata.rb
has 268 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Api
class MediaMetadata
# accepts '111', '11.123', not '.11'
OFFSET_REGEXP = /^-?(\d+\.)?\d+$/
Method check_uploader
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def check_uploader
#do_authorize_class - not used, this action does a custom auth
get_project_site
# current user should be the harvester
- Read upRead up
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 filter_settings
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def self.filter_settings
{
valid_fields: [:id, :name, :description, :creator_id,
:created_at,
:updater_id,
- Read upRead up
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 Config
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class Config
class << self
@is_resque_worker = false
# Is this a resque_worker?
# @return [Boolean]
Method registered
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.registered(app)
app.get '/statuses' do
@start = params[:start].to_i
Method filter_settings
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.filter_settings(priority_algorithm = nil)
result = {
valid_fields: [
:id, :dataset_id, :audio_recording_id, :start_time_seconds,
:end_time_seconds, :order, :creator_id, :created_at, :priority
File audio_ffmpeg.rb
has 261 lines of code (exceeds 250 allowed). Consider refactoring. Open
module BawAudioTools
# Used to manipulate the ffmpeg command line tool
class AudioFfmpeg
ERROR_FRAME_SIZE_1 = 'Could not find codec parameters for stream [0-9]+ \\(Audio\\: [a-zA-Z0-9]+\\, [0-9]+ channels\\, [a-zA-Z0-9]+\\)\\: unspecified frame size'
ERROR_FRAME_SIZE_2 = 'Failed to read frame size: Could not seek to [0-9]+\\.'