| Conditions | 13 |
| Paths | 120 |
| Total Lines | 72 |
| Code Lines | 44 |
| 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 |
||
| 104 | public function getSlackData(array $record) |
||
| 105 | { |
||
| 106 | $dataArray = array(); |
||
| 107 | $record = $this->excludeFields($record); |
||
| 108 | |||
| 109 | if ($this->username) { |
||
| 110 | $dataArray['username'] = $this->username; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($this->channel) { |
||
| 114 | $dataArray['channel'] = $this->channel; |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($this->formatter && !$this->useAttachment) { |
||
| 118 | $message = $this->formatter->format($record); |
||
| 119 | } else { |
||
| 120 | $message = $record['message']; |
||
| 121 | } |
||
| 122 | |||
| 123 | if ($this->useAttachment) { |
||
| 124 | $attachment = array( |
||
| 125 | 'fallback' => $message, |
||
| 126 | 'text' => $message, |
||
| 127 | 'color' => $this->getAttachmentColor($record['level']), |
||
| 128 | 'fields' => array(), |
||
| 129 | 'mrkdwn_in' => array('fields'), |
||
| 130 | 'ts' => $record['datetime']->getTimestamp() |
||
| 131 | ); |
||
| 132 | |||
| 133 | if ($this->useShortAttachment) { |
||
| 134 | $attachment['title'] = $record['level_name']; |
||
| 135 | } else { |
||
| 136 | $attachment['title'] = 'Message'; |
||
| 137 | $attachment['fields'][] = $this->generateAttachmentField('Level', $record['level_name']); |
||
| 138 | } |
||
| 139 | |||
| 140 | |||
| 141 | if ($this->includeContextAndExtra) { |
||
| 142 | foreach (array('extra', 'context') as $key) { |
||
| 143 | if (empty($record[$key])) { |
||
| 144 | continue; |
||
| 145 | } |
||
| 146 | |||
| 147 | if ($this->useShortAttachment) { |
||
| 148 | $attachment['fields'][] = $this->generateAttachmentField( |
||
| 149 | ucfirst($key), |
||
| 150 | $record[$key] |
||
| 151 | ); |
||
| 152 | } else { |
||
| 153 | // Add all extra fields as individual fields in attachment |
||
| 154 | $attachment['fields'] = array_merge( |
||
| 155 | $attachment['fields'], |
||
| 156 | $this->generateAttachmentFields($record[$key]) |
||
| 157 | ); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | $dataArray['attachments'] = array($attachment); |
||
| 163 | } else { |
||
| 164 | $dataArray['text'] = $message; |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($this->userIcon) { |
||
| 168 | if (filter_var($this->userIcon, FILTER_VALIDATE_URL)) { |
||
| 169 | $dataArray['icon_url'] = $this->userIcon; |
||
| 170 | } else { |
||
| 171 | $dataArray['icon_emoji'] = ":{$this->userIcon}:"; |
||
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | return $dataArray; |
||
| 176 | } |
||
| 295 |