Project::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 0
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
ccs 20
cts 20
cp 1
crap 4
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\Exception;
10
use WebMarketingROI\OptimizelyPHP\Resource\v2\WebSnippet;
11
12
/**
13
 * An Optimizely project.
14
 */
15
class Project
16
{
17
    /**
18
     * The name of the project
19
     * @var string 
20
     */
21
    private $name;
22
    
23
    /**
24
     * The account the project is associated with
25
     * @var integer 
26
     */
27
    private $accountId;
28
    
29
    /**
30
     * The significance level at which you would like to declare winning and 
31
     * losing variations. A lower number minimizes the time needed to declare a 
32
     * winning or losing variation, but increases the risk that your results 
33
     * aren't true winners and losers. The precision for this number is up to 4 
34
     * decimal places.
35
     * 
36
     * @var number 
37
     */
38
    private $confidenceThreshold;
39
    
40
    /**
41
     * The ID of a Dynamic Customer Profile Service associated with this project.
42
     * @var integer 
43
     */
44
    private $dcpServiceId;
45
    
46
    /**
47
     * The platform of the project. Can be 'web', 'ios', 'android' or 'custom'.
48
     * @var string 
49
     */
50
    private $platform;
51
    
52
    /**
53
     * The language to generate example code in.
54
     * @var array[string]
55
     */
56
    private $sdks;
57
    
58
    /**
59
     * The current status of the project. Can be 'active' or 'archived'.
60
     * @var string 
61
     */
62
    private $status;
63
    
64
    /**
65
     * Web snippet-specific configuration for this project.
66
     * @var WebSnippet 
67
     */
68
    private $webSnippet;
69
    
70
    /**
71
     * The time that the project was originally created
72
     * @var string 
73
     */
74
    private $created;
75
    
76
    /**
77
     * The unique identifier for the project.
78
     * @var integer 
79
     */
80
    private $id;
81
    
82
    /**
83
     * Whether or not this project was created under Optimizely Classic.
84
     * @var boolean 
85
     */
86
    private $isClassic;
87
    
88
    /**
89
     * The time the project was last modified
90
     * @var string 
91
     */
92
    private $lastModified;
93
    
94
    /**
95
     * The token used to identify your mobile app to Optimizely. (mobile only)
96
     * @var string 
97
     */
98
    private $socketToken;
99
    
100
    /**
101
     * A short description of the Project
102
     * @var string 
103
     */
104
    private $description;
105
    
106
    /**
107
     * Constructor.
108
     */
109 8
    public function __construct($options = array())
110
    {
111 8
        foreach ($options as $name=>$value) {
112
            switch ($name) {                
113 6
                case 'name': $this->setName($value); break;
114 6
                case 'account_id': $this->setAccountId($value); break;
115 6
                case 'confidence_threshold': $this->setConfidenceThreshold($value); break;
116 6
                case 'dcp_service_id': $this->setDcpServiceId($value); break;
117 6
                case 'platform': $this->setPlatform($value); break;
118 6
                case 'sdks': $this->setSdks($value); break;
119 6
                case 'status': $this->setStatus($value); break;
120 6
                case 'web_snippet': {
121 6
                    $webSnippet = new WebSnippet($value);
122 6
                    $this->setWebSnippet($webSnippet); 
123 6
                    break;
124
                }
125 6
                case 'created': $this->setCreated($value); break;
126 6
                case 'id': $this->setId($value); break;
127 5
                case 'is_classic': $this->setIsClassic($value); break;
128 5
                case 'last_modified': $this->setLastModified($value); break;
129 5
                case 'socket_token': $this->setSocketToken($value); break;
130
                case 'description': $this->setDescription($value); break;
131
                default:
132 6
                    throw new Exception('Unknown option found in the Project entity: ' . $name);
133
            }
134
        }
135 8
    }
136
    
137
    /**
138
     * Returns this object as array.
139
     */
140 3
    public function toArray()
141
    {
142
        $options = array(
143 3
            'name' => $this->getName(),
144 3
            'account_id' => $this->getAccountId(),
145 3
            'confidence_threshold' => $this->getConfidenceThreshold(),
146 3
            'dcp_service_id' => $this->getDcpServiceId(),
147 3
            'platform' => $this->getPlatform(),
148 3
            'sdks' => $this->getSdks(),
149 3
            'status' => $this->getStatus(),
150 3
            'web_snippet' => $this->getWebSnippet()?$this->getWebSnippet()->toArray():null,
151 3
            'created' => $this->getCreated(),
152 3
            'id' => $this->getId(),
153 3
            'is_classic' => $this->getIsClassic(),
154 3
            'last_modified' => $this->getLastModified(),
155 3
            'socket_token' => $this->getSocketToken(),
156 3
            'description' => $this->getDescription(),
157
        );
158
        
159
        // Remove options with empty values
160 3
        $cleanedOptions = array();
161 3
        foreach ($options as $name=>$value) {
162 3
            if ($value!==null)
163 3
                $cleanedOptions[$name] = $value;
164
        }
165
        
166 3
        return $cleanedOptions;
167
    }
168
    
169 7
    public function getName()
170
    {
171 7
        return $this->name;
172
    }
173
    
174 7
    public function setName($name)
175
    {
176 7
        $this->name = $name;
177 7
    }
178
    
179 5
    public function getAccountId()
180
    {
181 5
        return $this->accountId;
182
    }
183
    
184 7
    public function setAccountId($accountId)
185
    {
186 7
        $this->accountId = $accountId;
187 7
    }
188
    
189 4
    public function getConfidenceThreshold()
190
    {
191 4
        return $this->confidenceThreshold;
192
    }
193
    
194 3
    public function setConfidenceThreshold($confidenceThreshold)
195
    {
196 3
        $this->confidenceThreshold = $confidenceThreshold;
197 3
    }
198
    
199 4
    public function getDcpServiceId()
200
    {
201 4
        return $this->dcpServiceId;
202
    }
203
    
204 3
    public function setDcpServiceId($dcpServiceId)
205
    {
206 3
        $this->dcpServiceId = $dcpServiceId;
207 3
    }
208
    
209 4
    public function getPlatform()
210
    {
211 4
        return $this->platform;
212
    }
213
    
214 4
    public function setPlatform($platform)
215
    {
216 4
        $this->platform = $platform;
217 4
    }
218
    
219 4
    public function getSdks()
220
    {
221 4
        return $this->sdks;
222
    }
223
    
224 2
    public function setSdks($sdks)
225
    {
226 2
        $this->sdks = $sdks;
227 2
    }
228
    
229 4
    public function getStatus()
230
    {
231 4
        return $this->status;
232
    }
233
    
234 3
    public function setStatus($status)
235
    {
236 3
        $this->status = $status;
237 3
    }
238
    
239 5
    public function getWebSnippet()
240
    {
241 5
        return $this->webSnippet;
242
    }
243
    
244 7
    public function setWebSnippet($webSnippet)
245
    {
246 7
        $this->webSnippet = $webSnippet;
247 7
    }
248
    
249 5
    public function getCreated()
250
    {
251 5
        return $this->created;
252
    }
253
    
254 7
    public function setCreated($created)
255
    {
256 7
        $this->created = $created;
257 7
    }
258
    
259 5
    public function getId()
260
    {
261 5
        return $this->id;
262
    }
263
    
264 7
    public function setId($id)
265
    {
266 7
        $this->id = $id;
267 7
    }
268
    
269 5
    public function getIsClassic()
270
    {
271 5
        return $this->isClassic;
272
    }
273
    
274 6
    public function setIsClassic($isClassic)
275
    {
276 6
        $this->isClassic = $isClassic;
277 6
    }
278
    
279 5
    public function getLastModified()
280
    {
281 5
        return $this->lastModified;
282
    }
283
    
284 6
    public function setLastModified($lastModified)
285
    {
286 6
        $this->lastModified = $lastModified;
287 6
    }
288
    
289 5
    public function getSocketToken()
290
    {
291 5
        return $this->socketToken;
292
    }
293
    
294 6
    public function setSocketToken($socketToken)
295
    {
296 6
        $this->socketToken = $socketToken;
297 6
    }
298
    
299 3
    public function getDescription()
300
    {
301 3
        return $this->description;
302
    }
303
    
304
    public function setDescription($description)
305
    {
306
        $this->description = $description;
307
    }
308
}
309
310
311
312