DiscussConversationPresenter::conversationUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Models\Presenters;
6
7
use Illuminate\Database\Eloquent\Casts\Attribute;
8
9
trait DiscussConversationPresenter
10
{
11
    /**
12
     * We must decrement the post count due to the first post being counted.
13
     *
14
     * @return Attribute
15
     */
16
    protected function postCountFormated(): Attribute
17
    {
18
        return Attribute::make(
19
            get: fn () => $this->post_count - 1
20
        );
21
    }
22
23
    /**
24
     * Get the conversation url.
25
     *
26
     * @return Attribute
27
     */
28
    protected function conversationUrl(): Attribute
29
    {
30
        return Attribute::make(
31
            get: fn () => route('discuss.conversation.show', ['slug' => $this->slug, 'id' => $this->getKey()])
0 ignored issues
show
Bug introduced by
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            get: fn () => route('discuss.conversation.show', ['slug' => $this->slug, 'id' => $this->/** @scrutinizer ignore-call */ getKey()])
Loading history...
32
        );
33
    }
34
35
    /**
36
     * Get the last page number for the conversation.
37
     *
38
     * @return Attribute
39
     */
40
    protected function lastPage(): Attribute
41
    {
42
        return Attribute::make(
43
            get: function () {
44
                $posts = $this->post_count_formated;
45
46
                if ($this->is_solved) {
47
                    $posts = $posts - 1;
48
                }
49
50
                $page = (int) ceil($posts / config('xetaravel.pagination.discuss.post_per_page'));
51
52
                return $page ?: 1;
53
            }
54
        );
55
    }
56
}
57