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