Completed
Push — master ( 665158...0a74c8 )
by John
01:17
created

Simple.initialize()   F

Complexity

Conditions 11

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 36
rs 3.1764
cc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A Simple.url() 0 3 1
A Simple.content_type() 0 4 3
A Simple.headers() 0 3 1
A Simple.method() 0 3 1
A Simple.body() 0 3 1
A Simple.params() 0 3 1

How to fix   Complexity   

Complexity

Complex classes like Simple.initialize() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
module RingCentralSdk::REST::Request
2
  class Simple < RingCentralSdk::REST::Request::Base
3
    def initialize(opts = {})
4
      @method = opts[:method]
5
      @url = opts[:url]
6
      @params = opts[:params]
7
      @headers = opts[:headers]
8
      @body = opts[:body].nil? ? {} : opts[:body]
9
      if @body.is_a? Hash 
10
        @headers = {} unless @headers.is_a? Hash 
11
        @headers['Content-Type'] = 'application/json'
12
      end
13
14
      def content_type
15
        ct = @headers.is_a?(Hash) \
16
          ? @headers['Content-Type'] || '' : 'application/json'
17
      end
18
19
      def method
20
        @method
21
      end
22
23
      def url
24
        @url
25
      end
26
27
      def params
28
        @params
29
      end
30
31
      def headers
32
        @headers
33
      end
34
35
      def body
36
        @body
37
      end
38
    end
39
  end
40
end
41