Completed
Push — master ( 96059f...fe2237 )
by Oleg
06:07
created

Schedule   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 87
ccs 33
cts 36
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 12 5
A toArray() 0 17 3
A getStartTime() 0 4 1
A setStartTime() 0 4 1
A getStopTime() 0 4 1
A setStopTime() 0 4 1
A getTimezone() 0 4 1
A setTimezone() 0 4 1
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 12 October 2016
5
 * @copyright (c) 2016, Web Marketing ROI
6
 */
7
namespace WebMarketingROI\OptimizelyPHP\Resource\v2;
8
9
use WebMarketingROI\OptimizelyPHP\Exception;
10
11
/**
12
 * Optimizely schedule.
13
 */
14
class Schedule
15
{
16
    /**
17
     * The start time for the Experiment
18
     * @var string 
19
     */
20
    private $startTime;
21
    
22
    /**
23
     * The stop time for the Experiment
24
     * @var string 
25
     */
26
    private $stopTime;
27
    
28
    /**
29
     * The time zone to use for Experiment start/stop times
30
     * @var string 
31
     */
32
    private $timezone;
33
    
34
    /**
35
     * Constructor.
36
     */
37 7
    public function __construct($options = array())
38
    {
39 7
        foreach ($options as $name=>$value) {
40
            switch ($name) {                
41 6
                case 'start_time': $this->setStartTime($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...
42 6
                case 'stop_time': $this->setStopTime($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...
43 6
                case 'time_zone': $this->setTimezone($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...
44
                default:
45
                    throw new Exception('Unknown option found in the Schedule entity: ' . $name);
46
            }
47 7
        }
48 7
    }
49
    
50
    /**
51
     * Returns this object as array.
52
     */
53 3
    public function toArray()
54
    {
55
        $options = array(
56 3
            'start_time' => $this->getStartTime(),
57 3
            'stop_time' => $this->getStopTime(),
58 3
            'time_zone' => $this->getTimezone(),            
59 3
        );
60
        
61
        // Remove options with empty values
62 3
        $cleanedOptions = array();
63 3
        foreach ($options as $name=>$value) {
64 3
            if ($value!==null)
65 3
                $cleanedOptions[$name] = $value;
66 3
        }
67
        
68 3
        return $cleanedOptions;
69
    }
70
    
71 4
    public function getStartTime()
72
    {
73 4
        return $this->startTime;
74
    }
75
    
76 7
    public function setStartTime($startTime)
77
    {
78 7
        $this->startTime = $startTime;
79 7
    }
80
    
81 3
    public function getStopTime()
82
    {
83 3
        return $this->stopTime;
84
    }
85
    
86 7
    public function setStopTime($stopTime)
87
    {
88 7
        $this->stopTime = $stopTime;
89 7
    }
90
    
91 4
    public function getTimezone()
92
    {
93 4
        return $this->timezone;
94
    }
95
    
96 6
    public function setTimezone($timezone)
97
    {
98 6
        $this->timezone = $timezone;
99 6
    }
100
}
101
102
103
104
105
106
107
108