Passed
Push — 5.0.0 ( 9d1037...fbd7bb )
by Fèvre
05:16
created

DiscussConversationRepository::update()   B

Complexity

Conditions 10
Paths 68

Size

Total Lines 38
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 21
nc 68
nop 2
dl 0
loc 38
rs 7.6666
c 1
b 0
f 0

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Models\Repositories;
6
7
use Xetaravel\Models\DiscussConversation;
8
9
class DiscussConversationRepository
10
{
11
    /**
12
     * Find the previous conversation related to the given conversation.
13
     *
14
     * @param DiscussConversation $conversation
15
     *
16
     * @return DiscussConversation|null
17
     */
18
    public static function findPreviousConversation(DiscussConversation $conversation): ?DiscussConversation
19
    {
20
        return DiscussConversation::where('category_id', $conversation->category->getKey())
21
            ->where('created_at', '<', $conversation->created_at)
22
            ->orderBy('created_at', 'desc')
23
            ->first();
24
    }
25
}
26