Completed
Push — dev ( 73864e...ffd8f7 )
by Fike
38s
created

Parameter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 12.5 %

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
dl 4
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A eql? 4 4 2
A initialize() 0 4 1
A hash() 0 3 1
A to_s() 0 4 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
# frozen_string_literal: true
2
3
require_relative '../type'
4
5
module AMA
6
  module Entity
7
    class Mapper
8
      class Type
9
        # A reference for parameter defined in particular type
10
        # Acts as a proxy, delegating method calls to whatever lies as specified
11
        # parameter in owner
12
        class Parameter < Type
13
          attr_reader :owner
14
          attr_reader :id
15
16
          # @param [AMA::Entity::Mapper::Type] owner
17
          # @param [Symbol] id
18
          def initialize(owner, id)
19
            @owner = owner
20
            @id = id
21
          end
22
23
          def to_s
24
            "Parameter (reference) type for variable type :#{id} " \
25
              "(declared in #{owner})"
26
          end
27
28
          def hash
29
            @owner.hash ^ @id.hash
30
          end
31
32 View Code Duplication
          def eql?(other)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
33
            return false unless other.is_a?(self.class)
34
            @owner == other.owner && @id == other.id
35
          end
36
37
          Type.instance_methods.each do |method|
38
            next if method_defined?(method)
39
            define_method(method) do |*args|
40
              @owner.parameters[@id].send(method, *args)
41
            end
42
          end
43
        end
44
      end
45
    end
46
  end
47
end
48