OptimizationProblem   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 44.74 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 38
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 9 9 1
A optimize() 8 8 1
A get() 0 13 2
A url() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
module Route4me
2
  class OptimizationProblem
3
    def self.url
4
      '/api.v4/optimization_problem.php'
5
    end
6
7
    def self.get(params={})
8
      get = Util.extract(params, [
9
        :optimization_problem_id, :wait_for_final_state,
10
        :state, :limit, :offset
11
      ])
12
13
      optimization = Route4me.request(:get, self.url, get: get)
14
      if (optimization[:optimizations]).nil?
15
        optimization
16
      else
17
        optimization[:optimizations]
18
      end
19
    end
20
21 View Code Duplication
    def self.optimize(params={})
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
22
      json = Util.extract(params, [:addresses, :parameters])
23
      get = Util.extract(params, [
24
        :directions, :format, :route_path_output, :optimized_callback_url
25
      ])
26
27
      Route4me.request(:post, self.url, get: get, json: json)
28
    end
29
30 View Code Duplication
    def self.update(params={})
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
31
      json = Util.extract(params, [:addresses, :parameters])
32
      get = Util.extract(params, [
33
        :optimization_problem_id, :directions, :format,
34
        :route_path_output, :reoptimize
35
      ])
36
37
      Route4me.request(:post, self.url, get: get, json: json)
38
    end
39
  end
40
end
41