Completed
Push — master ( 0ca99d...7c70a3 )
by Oleg
02:52
created

Project::__construct()   C

Complexity

Conditions 14
Paths 14

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 14.4973

Importance

Changes 0
Metric Value
cc 14
eloc 20
nc 14
nop 1
dl 0
loc 25
ccs 19
cts 22
cp 0.8636
crap 14.4973
rs 5.0864
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 06 October 2016
5
 * @copyright (c) 2016, Web Marketing ROI
6
 */
7
namespace WebMarketingROI\OptimizelyPHP\Resource\v2;
8
9
use WebMarketingROI\OptimizelyPHP\Resource\v2\WebSnippet;
10
11
/**
12
 * An Optimizely project.
13
 */
14
class Project
15
{
16
    /**
17
     * The name of the project
18
     * @var string 
19
     */
20
    private $name;
21
    
22
    /**
23
     * The account the project is associated with
24
     * @var integer 
25
     */
26
    private $accountId;
27
    
28
    /**
29
     * The significance level at which you would like to declare winning and 
30
     * losing variations. A lower number minimizes the time needed to declare a 
31
     * winning or losing variation, but increases the risk that your results 
32
     * aren't true winners and losers. The precision for this number is up to 4 
33
     * decimal places.
34
     * 
35
     * @var number 
36
     */
37
    private $confidenceThreshold;
38
    
39
    /**
40
     * The ID of a Dynamic Customer Profile Service associated with this project.
41
     * @var integer 
42
     */
43
    private $dcpServiceId;
44
    
45
    /**
46
     * The platform of the project. Can be 'web', 'ios', 'android' or 'custom'.
47
     * @var string 
48
     */
49
    private $platform;
50
    
51
    /**
52
     * The current status of the project. Can be 'active' or 'archived'.
53
     * @var string 
54
     */
55
    private $status;
56
    
57
    /**
58
     * Web snippet-specific configuration for this project.
59
     * @var WebSnippet 
60
     */
61
    private $webSnippet;
62
    
63
    /**
64
     * The time that the project was originally created
65
     * @var string 
66
     */
67
    private $created;
68
    
69
    /**
70
     * The unique identifier for the project.
71
     * @var integer 
72
     */
73
    private $id;
74
    
75
    /**
76
     * Whether or not this project was created under Optimizely Classic.
77
     * @var boolean 
78
     */
79
    private $isClassic;
80
    
81
    /**
82
     * The time the project was last modified
83
     * @var string 
84
     */
85
    private $lastModified;
86
    
87
    /**
88
     * The token used to identify your mobile app to Optimizely. (mobile only)
89
     * @var string 
90
     */
91
    private $socketToken;
92
    
93
    /**
94
     * Constructor.
95
     */
96 7
    public function __construct($options = array())
97
    {
98 7
        foreach ($options as $name=>$value) {
99
            switch ($name) {                
100 6
                case 'name': $this->setName($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
101 6
                case 'account_id': $this->setAccountId($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
102 6
                case 'confidence_threshold': $this->setConfidenceThreshold($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
103 6
                case 'dcp_service_id': $this->setDcpServiceId($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
104 6
                case 'platform': $this->setPlatform($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
105 6
                case 'status': $this->setStatus($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
106 6
                case 'web_snippet': {
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
107 6
                    $webSnippet = new WebSnippet($value);
108 6
                    $this->setWebSnippet($webSnippet); 
109 6
                    break;
110
                }
111 6
                case 'created': $this->setCreated($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
112 6
                case 'id': $this->setId($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
113 5
                case 'is_classic': $this->setIsClassic($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
114 5
                case 'last_modified': $this->setLastModified($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
115 5
                case 'socket_token': $this->setSocketToken($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
116
                default:
117
                    throw new \Exception('Unknown option: ' . $name);
118
            }
119 7
        }
120 7
    }
121
    
122
    /**
123
     * Returns this object as array.
124
     */
125 3
    public function toArray()
126
    {
127
        $options = array(
128 3
            'name' => $this->getName(),
129 3
            'account_id' => $this->getAccountId(),
130 3
            'confidence_threshold' => $this->getConfidenceThreshold(),
131 3
            'dcp_service_id' => $this->getDcpServiceId(),
132 3
            'platform' => $this->getPlatform(),
133 3
            'status' => $this->getStatus(),
134 3
            'web_snippet' => $this->getWebSnippet()?$this->getWebSnippet()->toArray():null,
135 3
            'created' => $this->getCreated(),
136 3
            'id' => $this->getId(),
137 3
            'is_classic' => $this->getIsClassic(),
138 3
            'last_modified' => $this->getLastModified(),
139 3
            'socket_token' => $this->getSocketToken()
140 3
        );
141
        
142
        // Remove options with empty values
143 3
        $cleanedOptions = array();
144 3
        foreach ($options as $name=>$value) {
145 3
            if ($value!==null)
146 3
                $cleanedOptions[$name] = $value;
147 3
        }
148
        
149 3
        return $cleanedOptions;
150
    }
151
    
152 7
    public function getName()
153
    {
154 7
        return $this->name;
155
    }
156
    
157 7
    public function setName($name)
158
    {
159 7
        $this->name = $name;
160 7
    }
161
    
162 5
    public function getAccountId()
163
    {
164 5
        return $this->accountId;
165
    }
166
    
167 7
    public function setAccountId($accountId)
168
    {
169 7
        $this->accountId = $accountId;
170 7
    }
171
    
172 4
    public function getConfidenceThreshold()
173
    {
174 4
        return $this->confidenceThreshold;
175
    }
176
    
177 3
    public function setConfidenceThreshold($confidenceThreshold)
178
    {
179 3
        $this->confidenceThreshold = $confidenceThreshold;
180 3
    }
181
    
182 4
    public function getDcpServiceId()
183
    {
184 4
        return $this->dcpServiceId;
185
    }
186
    
187 3
    public function setDcpServiceId($dcpServiceId)
188
    {
189 3
        $this->dcpServiceId = $dcpServiceId;
190 3
    }
191
    
192 4
    public function getPlatform()
193
    {
194 4
        return $this->platform;
195
    }
196
    
197 3
    public function setPlatform($platform)
198
    {
199 3
        $this->platform = $platform;
200 3
    }
201
    
202 4
    public function getStatus()
203
    {
204 4
        return $this->status;
205
    }
206
    
207 3
    public function setStatus($status)
208
    {
209 3
        $this->status = $status;
210 3
    }
211
    
212 5
    public function getWebSnippet()
213
    {
214 5
        return $this->webSnippet;
215
    }
216
    
217 7
    public function setWebSnippet($webSnippet)
218
    {
219 7
        $this->webSnippet = $webSnippet;
220 7
    }
221
    
222 5
    public function getCreated()
223
    {
224 5
        return $this->created;
225
    }
226
    
227 7
    public function setCreated($created)
228
    {
229 7
        $this->created = $created;
230 7
    }
231
    
232 5
    public function getId()
233
    {
234 5
        return $this->id;
235
    }
236
    
237 7
    public function setId($id)
238
    {
239 7
        $this->id = $id;
240 7
    }
241
    
242 5
    public function getIsClassic()
243
    {
244 5
        return $this->isClassic;
245
    }
246
    
247 6
    public function setIsClassic($isClassic)
248
    {
249 6
        $this->isClassic = $isClassic;
250 6
    }
251
    
252 5
    public function getLastModified()
253
    {
254 5
        return $this->lastModified;
255
    }
256
    
257 6
    public function setLastModified($lastModified)
258
    {
259 6
        $this->lastModified = $lastModified;
260 6
    }
261
    
262 5
    public function getSocketToken()
263
    {
264 5
        return $this->socketToken;
265
    }
266
    
267 6
    public function setSocketToken($socketToken)
268
    {
269 6
        $this->socketToken = $socketToken;
270 6
    }
271
}
272
273
274
275