| Conditions | 5 | 
| Paths | 1 | 
| Total Lines | 54 | 
| Code Lines | 35 | 
| 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  | 
            ||
| 40 | public function findMap(Query $query, array $options)  | 
            ||
| 41 |     { | 
            ||
| 42 | return $query  | 
            ||
| 43 |             ->formatResults(function ($notifications) use ($options) { | 
            ||
| 44 |                 return $notifications->map(function ($notification) use ($options) { | 
            ||
| 45 | $notification->data = unserialize($notification->data);  | 
            ||
| 46 | |||
| 47 |                     switch ($notification->type) { | 
            ||
| 48 | case 'conversation.reply':  | 
            ||
| 49 | $username = $notification->data['sender']->username;  | 
            ||
| 50 | $conversationTitle = Text::truncate($notification->data['conversation']->title, 50, ['ellipsis' => '...', 'exact' => false]);  | 
            ||
| 51 | |||
| 52 | //Check if the creator of the conversation is the current user.  | 
            ||
| 53 |                             if ($notification->data['conversation']->user_id === $options['session']->read('Auth.User.id')) { | 
            ||
| 54 | $notification->text = __(  | 
            ||
| 55 |                                     '<strong>{0}</strong> has replied in your conversation <strong>{1}</strong>.', | 
            ||
| 56 | h($username),  | 
            ||
| 57 | h($conversationTitle)  | 
            ||
| 58 | );  | 
            ||
| 59 |                             } else { | 
            ||
| 60 | $notification->text = __(  | 
            ||
| 61 |                                     '<strong>{0}</strong> has replied in the conversation <strong>{1}</strong>.', | 
            ||
| 62 | h($username),  | 
            ||
| 63 | h($conversationTitle)  | 
            ||
| 64 | );  | 
            ||
| 65 | }  | 
            ||
| 66 | |||
| 67 | $notification->link = Router::url(['controller' => 'conversations', 'action' => 'go', $notification->data['conversation']->last_message_id, 'prefix' => false]);  | 
            ||
| 68 | break;  | 
            ||
| 69 | |||
| 70 | case 'bot':  | 
            ||
| 71 | $notification->text = __(  | 
            ||
| 72 |                                 'Welcome on <strong>{0}</strong>! You can now post your first message in the Forum.', | 
            ||
| 73 |                                 \Cake\Core\Configure::read('Site.name') | 
            ||
| 74 | );  | 
            ||
| 75 | |||
| 76 | $notification->link = Router::url(['controller' => 'forum', 'action' => 'index', 'prefix' => 'forum']);  | 
            ||
| 77 | $notification->icon = $notification->data['icon'];  | 
            ||
| 78 | break;  | 
            ||
| 79 | |||
| 80 | case 'badge':  | 
            ||
| 81 | $notification->text = __(  | 
            ||
| 82 |                                 'You have unlock the badge "{0}".', | 
            ||
| 83 | $notification->data['badge']->name  | 
            ||
| 84 | );  | 
            ||
| 85 | |||
| 86 | $notification->link = Router::url(['_name' => 'users-profile', 'id' => $notification->data['user']->id, 'slug' => $notification->data['user']->username, '#' => 'badges', 'prefix' => false]);  | 
            ||
| 87 | break;  | 
            ||
| 88 | }  | 
            ||
| 89 | |||
| 90 | return $notification;  | 
            ||
| 91 | });  | 
            ||
| 92 | });  | 
            ||
| 93 | }  | 
            ||
| 94 | }  | 
            ||
| 95 |