| Conditions | 10 | 
| Paths | 68 | 
| Total Lines | 34 | 
| Code Lines | 18 | 
| Lines | 6 | 
| Ratio | 17.65 % | 
| 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 | ||
| 67 | public static function update(array $data, DiscussConversation $conversation): DiscussConversation | ||
| 68 |     { | ||
| 69 |         if (Auth::user()->hasPermission('manage.discuss.conversations')) { | ||
| 70 | $data['is_pinned'] = isset($data['is_pinned']) ? true : false; | ||
| 71 | $data['is_locked'] = isset($data['is_locked']) ? true : false; | ||
| 72 | |||
| 73 | View Code Duplication |             if ($conversation->is_pinned != $data['is_pinned'] && $data['is_pinned'] == true) { | |
| 74 | event(new ConversationWasPinnedEvent($conversation, Auth::user())); | ||
| 75 | } | ||
| 76 | |||
| 77 | View Code Duplication |             if ($conversation->is_locked != $data['is_locked'] && $data['is_locked'] == true) { | |
| 78 | event(new ConversationWasLockedEvent($conversation, Auth::user())); | ||
| 79 | } | ||
| 80 | |||
| 81 | $conversation->is_locked = $data['is_locked']; | ||
| 82 | $conversation->is_pinned = $data['is_pinned']; | ||
| 83 | } | ||
| 84 | |||
| 85 |         if ($conversation->title != $data['title']) { | ||
| 86 | event(new TitleWasChangedEvent($conversation, $data['title'], $conversation->title)); | ||
| 87 | |||
| 88 | $conversation->title = $data['title']; | ||
| 89 | } | ||
| 90 | |||
| 91 |         if ($conversation->category_id != $data['category_id']) { | ||
| 92 | event(new CategoryWasChangedEvent($conversation, $data['category_id'], $conversation->category_id)); | ||
| 93 | |||
| 94 | $conversation->category_id = $data['category_id']; | ||
| 95 | } | ||
| 96 | |||
| 97 | $conversation->save(); | ||
| 98 | |||
| 99 | return $conversation; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | 
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.