Updated

app/jobs / fetch_country_register_job.rb

B
47 lines of codes
4 methods
8.8 complexity/method
7 churn
35.16 complexity
18 duplications
require 'faraday' class FetchCountryRegisterJob < ApplicationJob
  1. FetchCountryRegisterJob has no descriptive comment
HOST = 'https://country.register.gov.uk' ENDPOINT = '/records.json?page-size=500' TIMEOUT = 5 rescue_from StandardError do |exception| Appsignal.send_exception exception end def perform
  1. FetchCountryRegisterJob#perform has approx 6 statements
countries.each do |country| location = Location.find_or_initialize_by(code: country['country']) location.name = country['name']
  1. FetchCountryRegisterJob#perform refers to 'location' more than self (maybe move it to another class?) Locations: 0 1 2 3 4
location.start_date = country['start-date']
  1. FetchCountryRegisterJob#perform refers to 'location' more than self (maybe move it to another class?) Locations: 0 1 2 3 4
location.end_date = country['end-date']
  1. FetchCountryRegisterJob#perform refers to 'location' more than self (maybe move it to another class?) Locations: 0 1 2 3 4
if location.changed? || location.new_record?
  1. FetchCountryRegisterJob#perform refers to 'location' more than self (maybe move it to another class?) Locations: 0 1 2 3 4
location.save!
  1. FetchCountryRegisterJob#perform refers to 'location' more than self (maybe move it to another class?) Locations: 0 1 2 3 4
end end end private def countries fetch_register.body.values.map { |x| x['item'].first }
  1. FetchCountryRegisterJob#countries has the variable name 'x'
end def faraday
  1. FetchCountryRegisterJob#faraday doesn't depend on instance state (maybe move it to another class?)
Faraday.new(HOST) do |f|
  1. FetchCountryRegisterJob#faraday has the variable name 'f'
f.response :follow_redirects f.response :json f.response :raise_error f.adapter :net_http_persistent end end def fetch_register
  1. Similar code found in 2 nodes Locations: 0 1
faraday.get(ENDPOINT) do |request| request.options[:timeout] = TIMEOUT
  1. FetchCountryRegisterJob#fetch_register calls 'request.options' 2 times Locations: 0 1
  2. FetchCountryRegisterJob#fetch_register refers to 'request' more than self (maybe move it to another class?) Locations: 0 1
request.options[:open_timeout] = TIMEOUT
  1. FetchCountryRegisterJob#fetch_register calls 'request.options' 2 times Locations: 0 1
  2. FetchCountryRegisterJob#fetch_register refers to 'request' more than self (maybe move it to another class?) Locations: 0 1
end end end