1 | <?php |
||
12 | class Schedule |
||
13 | { |
||
14 | /** |
||
15 | * The start time for the Experiment |
||
16 | * @var string |
||
17 | */ |
||
18 | private $startTime; |
||
19 | |||
20 | /** |
||
21 | * The stop time for the Experiment |
||
22 | * @var string |
||
23 | */ |
||
24 | private $stopTime; |
||
25 | |||
26 | /** |
||
27 | * The time zone to use for Experiment start/stop times |
||
28 | * @var string |
||
29 | */ |
||
30 | private $timezone; |
||
31 | |||
32 | /** |
||
33 | * Constructor. |
||
34 | */ |
||
35 | 7 | public function __construct($options = array()) |
|
36 | { |
||
37 | 7 | foreach ($options as $name=>$value) { |
|
38 | switch ($name) { |
||
39 | 6 | case 'start_time': $this->setStartTime($value); break; |
|
40 | 6 | case 'stop_time': $this->setStopTime($value); break; |
|
41 | 6 | case 'time_zone': $this->setTimezone($value); break; |
|
42 | default: |
||
43 | 6 | throw new \Exception('Unknown option: ' . $name); |
|
44 | } |
||
45 | } |
||
46 | 7 | } |
|
47 | |||
48 | /** |
||
49 | * Returns this object as array. |
||
50 | */ |
||
51 | 3 | public function toArray() |
|
52 | { |
||
53 | $options = array( |
||
54 | 3 | 'start_time' => $this->getStartTime(), |
|
55 | 3 | 'stop_time' => $this->getStopTime(), |
|
56 | 3 | 'time_zone' => $this->getTimezone(), |
|
57 | ); |
||
58 | |||
59 | // Remove options with empty values |
||
60 | 3 | $cleanedOptions = array(); |
|
61 | 3 | foreach ($options as $name=>$value) { |
|
62 | 3 | if ($value!==null) |
|
63 | 3 | $cleanedOptions[$name] = $value; |
|
64 | } |
||
65 | |||
66 | 3 | return $cleanedOptions; |
|
67 | } |
||
68 | |||
69 | 4 | public function getStartTime() |
|
73 | |||
74 | 7 | public function setStartTime($startTime) |
|
78 | |||
79 | 3 | public function getStopTime() |
|
83 | |||
84 | 7 | public function setStopTime($stopTime) |
|
88 | |||
89 | 4 | public function getTimezone() |
|
93 | |||
94 | 6 | public function setTimezone($timezone) |
|
98 | } |
||
99 | |||
100 | |||
106 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.