Completed
Pull Request — master (#6)
by Nick
02:39
created

Probability   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 129
Duplicated Lines 6.98 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 2
dl 9
loc 129
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContentId() 0 4 1
A setContentConnectorId() 9 9 2
A getContentConnectorId() 0 4 1
A setContentViewId() 0 9 2
A getContentViewId() 0 4 1
A setFraction() 0 12 4
A getFraction() 0 4 1
A setContentId() 0 9 2

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
<?php
2
3
namespace Acquia\LiftClient\Entity;
4
5
use Acquia\LiftClient\Exception\LiftSdkException;
6
7
class Probability extends \ArrayObject
8
{
9
    use EntityTrait;
10
11
  /**
12
   * @param array $array
13
   */
14
  public function __construct(array $array = [])
15
  {
16
      parent::__construct($array);
17
  }
18
19
  /**
20
   * Sets the 'id' parameter.
21
   *
22
   * @param string $contentId
23
   *
24
   * @throws \Acquia\LiftClient\Exception\LiftSdkException
25
   *
26
   * @return \Acquia\LiftClient\Entity\Probability
27
   */
28
  public function setContentId($contentId)
29
  {
30
      if (!is_string($contentId)) {
31
          throw new LiftSdkException('Argument must be an instance of string.');
32
      }
33
      $this['id'] = $contentId;
34
35
      return $this;
36
  }
37
38
  /**
39
   * Gets the 'id' parameter.
40
   *
41
   * @return string The Identifier of the Content Identifier
42
   */
43
  public function getContentId()
44
  {
45
      return $this->getEntityValue('id', '');
46
  }
47
48
  /**
49
   * @param string $contentConnectorId
50
   *
51
   * @throws \Acquia\LiftClient\Exception\LiftSdkException
52
   *
53
   * @return \Acquia\LiftClient\Entity\Probability
54
   */
55 View Code Duplication
  public function setContentConnectorId($contentConnectorId = 'content_hub')
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
  {
57
      if (!is_string($contentConnectorId)) {
58
          throw new LiftSdkException('Argument must be an instance of string.');
59
      }
60
      $this['content_connector_id'] = $contentConnectorId;
61
62
      return $this;
63
  }
64
65
  /**
66
   * Gets the 'content_connector_id' parameter.
67
   *
68
   * @return string
69
   */
70
  public function getContentConnectorId()
71
  {
72
      return $this->getEntityValue('content_connector_id', 'content_hub');
73
  }
74
75
  /**
76
   * Sets the 'content_view_id' parameter.
77
   *
78
   * @param string $contentViewId
79
   *
80
   * @throws \Acquia\LiftClient\Exception\LiftSdkException
81
   *
82
   * @return \Acquia\LiftClient\Entity\Probability
83
   */
84
  public function setContentViewId($contentViewId)
85
  {
86
      if (!is_string($contentViewId)) {
87
          throw new LiftSdkException('Argument must be an instance of string.');
88
      }
89
      $this['content_view_id'] = $contentViewId;
90
91
      return $this;
92
  }
93
94
  /**
95
   * Gets the 'content_view_id' parameter.
96
   *
97
   * @return string The Content View Mode Identifier
98
   */
99
  public function getContentViewId()
100
  {
101
      return $this->getEntityValue('content_view_id', '');
102
  }
103
104
  /**
105
   * Sets the 'fraction' parameter.
106
   *
107
   * @param int|float $fraction
108
   *
109
   * @throws \Acquia\LiftClient\Exception\LiftSdkException
110
   *
111
   * @return \Acquia\LiftClient\Entity\Probability
112
   */
113
  public function setFraction($fraction)
114
  {
115
      if (!is_numeric($fraction)) {
116
          throw new LiftSdkException('Argument must be an instance of any numeric type (int|float).');
117
      }
118
      if ($fraction > 1 || $fraction < 0) {
119
          throw new LiftSdkException('Argument must be between 0 and 1 or those values themselves.');
120
      }
121
      $this['fraction'] = $fraction;
122
123
      return $this;
124
  }
125
126
  /**
127
   * Gets the 'fraction' parameter.
128
   *
129
   * @return int|float The fraction
130
   */
131
  public function getFraction()
132
  {
133
      return $this->getEntityValue('fraction', 0);
134
  }
135
}
136