| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 27 | static function fromArray($array = array()) { |
||
|
|
|||
| 28 | $required = array('name','date','path','items'); |
||
| 29 | $report = new Report(); |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Check if all required fields are being set. |
||
| 33 | */ |
||
| 34 | foreach ($required as $req) { |
||
| 35 | if (isset($array[$req]) == false) { |
||
| 36 | throw new Exception\RuntimeException('Could not create a report from this array field ' . $req . ' was not set the following fields are required (' . implode(',', $required) . ')'); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | $report->setName($array['name']); |
||
| 40 | $report->setDate($array['date']); |
||
| 41 | $report->setPath($array['path']); |
||
| 42 | $report->setItems($array['items']); |
||
| 43 | return $report; |
||
| 44 | } |
||
| 45 | |||
| 46 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.