Add   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 25
loc 25
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 13 13 1
A initialize() 4 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
# rubocop:disable Metrics/AbcSize
4
5
require_relative '../../../action'
6
7
module AMA
8
  module Chef
9
    module User
10 View Code Duplication
      class Action
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
        module Account
12
          module PrivateKey
13
            class Add < Action
14
              attr_accessor :account
15
              attr_accessor :key
16
17
              # @param [AMA::Chef::User::Model::Account] account
18
              # @param [AMA::Chef::User::Model::PrivateKey] key
19
              def initialize(account, key)
20
                @account = account
21
                @key = key
22
              end
23
24
              def apply(resource_factory)
25
                account = @account
26
                key = @key
27
                name = "#{account.id}:#{key.owner}:#{key.id}"
28
                resource_factory.ssh_private_key name do
29
                  id key.id.to_s
30
                  user account.id.to_s
31
                  content key.content.to_s
32
                  install_public_key key.install_public_key
33
                  passphrase key.passphrase unless key.passphrase.nil?
34
                  perform_validation key.validate
35
                end
36
              end
37
            end
38
          end
39
        end
40
      end
41
    end
42
  end
43
end
44