Noosfero/noosfero

View on GitHub
plugins/sniffer/lib/ext/products_plugin/product.rb

Summary

Maintainability
A
2 hrs
Test Coverage

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

  scope :sniffer_plugin_suppliers_products, ->enterprise {
    select("DISTINCT products_2.*, 'product' as view")
      .joins("INNER JOIN inputs ON products.id = inputs.product_id")
      .joins("INNER JOIN categories ON inputs.product_category_id = categories.id")
      .joins("INNER JOIN products products_2 ON categories.id = products_2.product_category_id")
Severity: Minor
Found in plugins/sniffer/lib/ext/products_plugin/product.rb and 3 other locations - About 25 mins to fix
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 33..43
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 109..119
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 122..132

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

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

  scope :sniffer_plugin_consumers_products, ->enterprise {
    select("DISTINCT products_2.*, profiles.id as consumer_profile_id, 'product' as view")
      .joins("INNER JOIN inputs ON products.id = inputs.product_id")
      .joins("INNER JOIN categories ON inputs.product_category_id = categories.id")
      .joins("INNER JOIN products products_2 ON categories.id = products_2.product_category_id")
Severity: Minor
Found in plugins/sniffer/lib/ext/products_plugin/product.rb and 3 other locations - About 25 mins to fix
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 13..23
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 109..119
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 122..132

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

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

  scope :sniffer_plugin_knowledge_consumers_interests, ->profile {
    from("articles")
      .select("DISTINCT articles.id AS knowledge_id, op.opportunity_id AS product_category_id, profiles.id as profile_id, 'knowledge' as view")
      .joins("INNER JOIN article_resources ON articles.id = article_resources.article_id")
      .joins("INNER JOIN sniffer_plugin_opportunities as op ON article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory'")
Severity: Minor
Found in plugins/sniffer/lib/ext/products_plugin/product.rb and 3 other locations - About 25 mins to fix
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 13..23
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 33..43
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 122..132

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

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

  scope :sniffer_plugin_knowledge_suppliers_interests, ->profile {
    from("articles")
      .select("DISTINCT articles.id AS knowledge_id, op.opportunity_id AS product_category_id, profiles.id as profile_id, 'knowledge' as view")
      .joins("INNER JOIN article_resources ON articles.id = article_resources.article_id")
      .joins("INNER JOIN sniffer_plugin_opportunities as op ON article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory'")
Severity: Minor
Found in plugins/sniffer/lib/ext/products_plugin/product.rb and 3 other locations - About 25 mins to fix
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 13..23
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 33..43
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 109..119

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

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

  scope :sniffer_plugin_knowledge_consumers_inputs, ->profile {
    select("DISTINCT products.*, articles.id AS knowledge_id, 'knowledge' as view")
      .joins("INNER JOIN inputs ON products.id = inputs.product_id")
      .joins("INNER JOIN article_resources ON article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory'")
      .joins("INNER JOIN articles ON article_resources.article_id = articles.id")
Severity: Minor
Found in plugins/sniffer/lib/ext/products_plugin/product.rb and 1 other location - About 20 mins to fix
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 97..106

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

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

  scope :sniffer_plugin_knowledge_suppliers_inputs, ->profile {
    select("DISTINCT products.*, profiles.id as supplier_profile_id, articles.id AS knowledge_id, 'knowledge' as view")
      .joins("INNER JOIN inputs ON products.id = inputs.product_id")
      .joins("INNER JOIN article_resources ON article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory'")
      .joins("INNER JOIN articles ON article_resources.article_id = articles.id")
Severity: Minor
Found in plugins/sniffer/lib/ext/products_plugin/product.rb and 1 other location - About 20 mins to fix
plugins/sniffer/lib/ext/products_plugin/product.rb on lines 85..94

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

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

There are no issues that match your filters.

Category
Status