| Conditions | 31 |
| Paths | 6080 |
| Total Lines | 45 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 74 | protected function validateItemData(stdClass $itemData) |
||
| 75 | { |
||
| 76 | $this->url = empty($itemData->url) ? '' : $itemData->url; |
||
| 77 | $this->title = empty($itemData->title) ? '' : $itemData->title; |
||
| 78 | $this->text = empty($itemData->text) ? '' : $itemData->text; |
||
| 79 | $this->custom = empty($itemData->custom) || !is_array($itemData->custom) ? [] : (array) $itemData->custom; |
||
| 80 | |||
| 81 | $this->icon = empty($itemData->icon) ? null : $itemData->icon; |
||
| 82 | |||
| 83 | if ($this->icon |
||
| 84 | && (empty($this->icon->url) || empty($this->icon->width) || empty($this->icon->height)) |
||
| 85 | ) { |
||
| 86 | throw new Exception(sprintf("Icon properties are missing in data form content item: %s", print_r($itemData, true))); |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->thumbnail = empty($itemData->thumbnail) ? null : $itemData->thumbnail; |
||
| 90 | |||
| 91 | if ($this->thumbnail |
||
| 92 | && (empty($this->thumbnail->url) || empty($this->thumbnail->width) || empty($this->thumbnail->height)) |
||
| 93 | ) { |
||
| 94 | throw new Exception(sprintf("Thumbnail URL is missing in data form content item: %s", print_r($itemData, true))); |
||
| 95 | } |
||
| 96 | |||
| 97 | $this->iframe = empty($itemData->iframe) ? null : $itemData->iframe; |
||
| 98 | |||
| 99 | if ($this->iframe && (empty($this->iframe->width) || empty($this->iframe->height))) { |
||
| 100 | throw new Exception(sprintf("Iframe size is wrong in data form content item: %s", print_r($itemData, true))); |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->lineItem = empty($itemData->lineItem) ? null : $itemData->lineItem; |
||
| 104 | |||
| 105 | if ($this->lineItem && empty($this->lineItem->scoreMaximum)) { |
||
| 106 | throw new Exception(sprintf("LineItem properties are missing in data form content item: %s", print_r($itemData, true))); |
||
| 107 | } |
||
| 108 | |||
| 109 | $this->available = empty($itemData->available) ? null : $itemData->available; |
||
| 110 | |||
| 111 | if ($this->available && empty($this->available->startDateTime) && empty($this->available->endDateTime)) { |
||
| 112 | throw new Exception(sprintf("LineItem properties are missing in data form content item: %s", print_r($itemData, true))); |
||
| 113 | } |
||
| 114 | |||
| 115 | $this->submission = empty($itemData->submission) ? null : $itemData->submission; |
||
| 116 | |||
| 117 | if ($this->submission && empty($this->submission->startDateTime) && empty($this->submission->endDateTime)) { |
||
| 118 | throw new Exception(sprintf("Submission properties are missing in data form content item: %s", print_r($itemData, true))); |
||
| 119 | } |
||
| 151 |