Showing 66 of 66 total issues
Method compute_shows
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def compute_shows
default_scope = self.class.default_scope
if default_scope.is_a?(Array)
Rails.logger.warn('Ignoring #scopes due to default scope being an array')
return default_scope
- 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
Function createMenuItem
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function createMenuItem(id, lang, label) {
var listItem = document.createElement('li');
var button = listItem.appendChild(document.createElement('button'));
button.setAttribute('id', id);
Method crawl_shows
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def crawl_shows
raise 'Crawling is not allowed.' unless Rails.configuration.allows_crawling
@current_url = "https://kitsu.io/api/edge/anime?page%5Blimit%5D=20&page%5Boffset%5D=0"
@has_next = true
- 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 airing_status_for
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def airing_status_for(show, default: 'unknown')
return default if show.starts_on.blank?
today_s_date = DateTime.now.utc
if show.starts_on < today_s_date
- 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 fetch_streaming_platforms_from_anilist
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def fetch_streaming_platforms_from_anilist
Rails.logger.info("[Shows::Anilist::Streamers] GET graphql.anilist.co: ANIME(##{anilist_id})")
data = fetch_data!.dig(:data, :Media)
return unless data.present?
- 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 detect_from
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.detect_from(urls_or_names)
urls_or_names = Array(urls_or_names) unless urls_or_names.is_a?(Array)
names = urls_or_names.map do |url_or_name|
if url_or_name.is_a?(String) || url_or_name.is_a?(Symbol)
- 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
Function login
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function login(error_p_id, waiting_p_id, success_p_id, form_id, callback) {
function edForm(form, readOnly) {
if (form && form.elements) {
var elements = form.elements;
[].forEach.call(elements, function(e) {
- 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 compute_shows
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def compute_shows
default_scope = self.class.default_scope
if default_scope.is_a?(Array)
Rails.logger.warn('Ignoring #scopes due to default scope being an array')
return default_scope
Method link_for
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def link_for(site, url)
if site.downcase =~ /official site/
method = persist ? :create! : :new
ShowUrl.send(method, url_type: :official, value: url, show: show)
else
- 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_or_update_show_for
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def create_or_update_show_for(data, airing_status, show_obj: nil)
fetched_attrs = data[:attributes]
synched_show = show_obj.present? ? show_obj : find_show_from_attributes(fetched_attrs)
if synched_show.persisted?
- 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 update_banner_and_poster_urls!
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def update_banner_and_poster_urls!(**options)
force = options[:force] || false
return nil unless persisted?
if !force
return true if poster_url? && banner_url?
- 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
Avoid deeply nested control flow statements. Open
if (episode.ratio !== undefined) {
var progressBar = $('div#progress_' + id);
ratioInfo = 'width: ' + parseInt(episode.ratio) + '%;';
progressBar.attr('style', ratioInfo);
progressBar.removeClass('hidden');
Method sync_show
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def sync_show
raise '`show` params is mandatory with sync_type: :show' unless show.present?
return unless show.synchable?
response = RestClient.get(request_show_url(show))
- 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 perform
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def perform
Show.published.each do |show|
next unless show.synchable? && show.reference_source == 'kitsu'
Shows::Kitsu::Get.perform(
- 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
Function goToNextId
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function goToNextId(currentId) {
console.log("Going to the next episode if any...");
$.ajax({
type: 'get',
url: '/json/get/episode/next?id=' + currentId + "&check_setting=true",
- 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 badges
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def badges
options = []
options << badge_options
options << { type: :light, text: t("anime.shows.airing_status.#{@show.status}") } unless @show.air_complete?
- 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
Function login
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function login(error_p_id, waiting_p_id, success_p_id, form_id, callback) {
Identical blocks of code found in 2 locations. Consider refactoring. Open
def prepare_variables(variables_param)
case variables_param
when String
if variables_param.present?
JSON.parse(variables_param) || {}
- 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 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
- 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
Method override_episodes_for
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def override_episodes_for(show)
#::Sync::Shows::ReactionCountJob.perform_later(show)
return if show.reference_id.blank?
response = RestClient.get(request_episodes_url(show))
- 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 sort_filters
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.sort_filters(*filters)
scope = all
filters.map do |filter|
scope = if filter.use_scope
scope = scope.send(filter.use_scope)
- 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"