Completed
Pull Request — master (#6)
by Nick
03:00
created

Probability   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 127
Duplicated Lines 7.09 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setContentId() 0 9 2
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

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 Entity
8
{
9
    /**
10
     * @param array $array
11
     */
12
    public function __construct(array $array = [])
13
    {
14
        parent::__construct($array);
15
    }
16
17
    /**
18
     * Sets the 'id' parameter.
19
     *
20
     * @param string $contentId
21
     *
22
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
23
     *
24
     * @return \Acquia\LiftClient\Entity\Probability
25
     */
26
    public function setContentId($contentId)
27
    {
28
        if (!is_string($contentId)) {
29
            throw new LiftSdkException('Argument must be an instance of string.');
30
        }
31
        $this['id'] = $contentId;
32
33
        return $this;
34
    }
35
36
    /**
37
     * Gets the 'id' parameter.
38
     *
39
     * @return string The Identifier of the Content Identifier
40
     */
41
    public function getContentId()
42
    {
43
        return $this->getEntityValue('id', '');
44
    }
45
46
    /**
47
     * @param string $contentConnectorId
48
     *
49
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
50
     *
51
     * @return \Acquia\LiftClient\Entity\Probability
52
     */
53 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...
54
    {
55
        if (!is_string($contentConnectorId)) {
56
            throw new LiftSdkException('Argument must be an instance of string.');
57
        }
58
        $this['content_connector_id'] = $contentConnectorId;
59
60
        return $this;
61
    }
62
63
    /**
64
     * Gets the 'content_connector_id' parameter.
65
     *
66
     * @return string
67
     */
68
    public function getContentConnectorId()
69
    {
70
        return $this->getEntityValue('content_connector_id', 'content_hub');
71
    }
72
73
    /**
74
     * Sets the 'content_view_id' parameter.
75
     *
76
     * @param string $contentViewId
77
     *
78
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
79
     *
80
     * @return \Acquia\LiftClient\Entity\Probability
81
     */
82
    public function setContentViewId($contentViewId)
83
    {
84
        if (!is_string($contentViewId)) {
85
            throw new LiftSdkException('Argument must be an instance of string.');
86
        }
87
        $this['content_view_id'] = $contentViewId;
88
89
        return $this;
90
    }
91
92
    /**
93
     * Gets the 'content_view_id' parameter.
94
     *
95
     * @return string The Content View Mode Identifier
96
     */
97
    public function getContentViewId()
98
    {
99
        return $this->getEntityValue('content_view_id', '');
100
    }
101
102
    /**
103
     * Sets the 'fraction' parameter.
104
     *
105
     * @param int|float $fraction
106
     *
107
     * @throws \Acquia\LiftClient\Exception\LiftSdkException
108
     *
109
     * @return \Acquia\LiftClient\Entity\Probability
110
     */
111
    public function setFraction($fraction)
112
    {
113
        if (!is_numeric($fraction)) {
114
            throw new LiftSdkException('Argument must be an instance of any numeric type (int|float).');
115
        }
116
        if ($fraction > 1 || $fraction < 0) {
117
            throw new LiftSdkException('Argument must be between 0 and 1 or those values themselves.');
118
        }
119
        $this['fraction'] = $fraction;
120
121
        return $this;
122
    }
123
124
    /**
125
     * Gets the 'fraction' parameter.
126
     *
127
     * @return int|float The fraction
128
     */
129
    public function getFraction()
130
    {
131
        return $this->getEntityValue('fraction', 0);
132
    }
133
}
134