1 | <?php |
||
12 | class Metric |
||
13 | { |
||
14 | /** |
||
15 | * The kind of a Metric |
||
16 | * @var string |
||
17 | */ |
||
18 | private $kind; |
||
19 | |||
20 | /** |
||
21 | * The unique identifier for the Metric |
||
22 | * @var integer |
||
23 | */ |
||
24 | private $id; |
||
25 | |||
26 | /** |
||
27 | * Constructor. |
||
28 | */ |
||
29 | 14 | public function __construct($options = array()) |
|
30 | { |
||
31 | 14 | foreach ($options as $name=>$value) { |
|
32 | switch ($name) { |
||
33 | 12 | case 'kind': $this->setKind($value); break; |
|
34 | 8 | case 'id': $this->setId($value); break; |
|
35 | default: |
||
36 | 12 | throw new \Exception('Unknown option: ' . $name); |
|
37 | } |
||
38 | } |
||
39 | 14 | } |
|
40 | |||
41 | /** |
||
42 | * Returns this object as array. |
||
43 | */ |
||
44 | 6 | public function toArray() |
|
45 | { |
||
46 | $options = array( |
||
47 | 6 | 'kind' => $this->getKind(), |
|
48 | 6 | 'id' => $this->getId(), |
|
49 | ); |
||
50 | |||
51 | // Remove options with empty values |
||
52 | 6 | $cleanedOptions = array(); |
|
53 | 6 | foreach ($options as $name=>$value) { |
|
54 | 6 | if ($value!==null) |
|
55 | 6 | $cleanedOptions[$name] = $value; |
|
56 | } |
||
57 | |||
58 | 6 | return $cleanedOptions; |
|
59 | } |
||
60 | |||
61 | 9 | public function getKind() |
|
65 | |||
66 | 14 | public function setKind($kind) |
|
70 | |||
71 | 6 | public function getId() |
|
75 | |||
76 | 9 | public function setId($id) |
|
80 | } |
||
81 | |||
82 | |||
86 |
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.