Completed
Push — master ( c7e879...390e33 )
by Fèvre
02:26
created

DiscussConversationPresenter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 3
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPostCountFormatedAttribute() 0 4 1
A getConversationUrlAttribute() 0 8 2
A getLastPageAttribute() 0 12 3
1
<?php
2
namespace Xetaravel\Models\Presenters;
3
4
use GrahamCampbell\Markdown\Facades\Markdown;
5
6
trait DiscussConversationPresenter
7
{
8
    /**
9
     * We must decrement the post count due to the first post being counted.
10
     *
11
     * @param int $count The actual post count cache.
0 ignored issues
show
Bug introduced by
There is no parameter named $count. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
12
     *
13
     * @return int
14
     */
15
    public function getPostCountFormatedAttribute(): int
16
    {
17
        return $this->post_count - 1;
0 ignored issues
show
Bug introduced by
The property post_count does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
    }
19
20
    /**
21
     * Get the conversation url.
22
     *
23
     * @return string
24
     */
25
    public function getConversationUrlAttribute(): string
26
    {
27
        if (!isset($this->slug)) {
28
            return '';
29
        }
30
31
        return route('discuss.conversation.show', ['slug' => $this->slug, 'id' => $this->getKey()]);
0 ignored issues
show
Bug introduced by
The property slug does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
    }
33
34
    /**
35
     * Get the last page number for the conversation.
36
     *
37
     * @return int
38
     */
39
    public function getLastPageAttribute(): int
40
    {
41
        $posts = $this->post_count_formated;
0 ignored issues
show
Bug introduced by
The property post_count_formated does not seem to exist. Did you mean post_count?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
43
        if ($this->is_solved) {
0 ignored issues
show
Bug introduced by
The property is_solved does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
            $posts = $posts - 1;
45
        }
46
47
        $page = ceil($posts / config('xetaravel.pagination.discuss.post_per_page'));
48
49
        return ($page) ? $page : 1;
50
    }
51
}
52