expertiza/expertiza

View on GitHub
app/models/simicheck_webservice.rb

Summary

Maintainability
A
1 hr
Test Coverage
F
32%

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

class SimiCheckWebService
  @@api_key = PLAGIARISM_CHECKER_CONFIG['simicheck_api_key']
  @@base_uri = 'https://www.simicheck.com/api'
  ############################################
  # Comparison Operations
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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. [13/10]
Open

  def self.upload_file(comparison_id, path_to_file)
    full_url = @@base_uri + '/upload_file/' + comparison_id
    file_to_upload = File.new(path_to_file, 'rb')
    json_body = { 'file' => file_to_upload } # don't use .to_json!
    RestClient::Request.execute(method: :put,
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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. [12/10]
Open

  def self.post_similarity_1xn(comparison_id, filename, callback_url = '')
    full_url = @@base_uri + '/similarity_1xn/' + comparison_id
    json_body = callback_url.empty? ? { 'filename' => filename }.to_json : { 'filename' => filename, 'callback_url' => callback_url }.to_json
    RestClient::Request.execute(method: :post,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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. [12/10]
Open

  def self.new_comparison(comparison_name = '')
    full_url = @@base_uri + '/comparison'
    json_body = { comparison_name: comparison_name }.to_json
    RestClient::Request.execute(method: :put,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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. [12/10]
Open

  def self.update_comparison(comparison_id, new_comparison_name)
    full_url = @@base_uri + '/comparison/' + comparison_id
    json_body = { comparison_name: new_comparison_name }.to_json
    RestClient::Request.execute(method: :post,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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. [12/10]
Open

  def self.get_similarity_1xn(comparison_id, filename)
    full_url = @@base_uri + '/similarity_1xn/' + comparison_id
    json_body = { 'filename' => filename }.to_json
    RestClient::Request.execute(method: :get,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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. [12/10]
Open

  def self.delete_files(comparison_id, filenames_to_delete)
    full_url = @@base_uri + '/delete_files/' + comparison_id
    json_body = { 'filenames' => filenames_to_delete }.to_json
    RestClient::Request.execute(method: :post,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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. [12/10]
Open

  def self.post_similarity_nxn(comparison_id, callback_url = '')
    full_url = @@base_uri + '/similarity_nxn/' + comparison_id
    json_body = callback_url.empty? ? {}.to_json : { 'callback_url' => callback_url }.to_json
    RestClient::Request.execute(method: :post,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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.

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

  def self.get_similarity_1xn(comparison_id, filename)
    full_url = @@base_uri + '/similarity_1xn/' + comparison_id
    json_body = { 'filename' => filename }.to_json
    RestClient::Request.execute(method: :get,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb and 1 other location - About 35 mins to fix
app/models/simicheck_webservice.rb on lines 120..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 34.

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 self.delete_files(comparison_id, filenames_to_delete)
    full_url = @@base_uri + '/delete_files/' + comparison_id
    json_body = { 'filenames' => filenames_to_delete }.to_json
    RestClient::Request.execute(method: :post,
                                url: full_url,
Severity: Minor
Found in app/models/simicheck_webservice.rb and 1 other location - About 35 mins to fix
app/models/simicheck_webservice.rb on lines 186..198

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

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

Missing top-level class documentation comment.
Open

class SimiCheckWebService
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

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

Replace class var @@api_key with a class instance var.
Open

  @@api_key = PLAGIARISM_CHECKER_CONFIG['simicheck_api_key']
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Replace class var @@base_uri with a class instance var.
Open

  @@base_uri = 'https://www.simicheck.com/api'
Severity: Minor
Found in app/models/simicheck_webservice.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

There are no issues that match your filters.

Category
Status