Completed
Push — master ( d44ef5...c7e879 )
by Fèvre
12s
created

DiscussLogPresenter::getTypeAttribute()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 22
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.6737
c 0
b 0
f 0
cc 6
eloc 19
nc 6
nop 0
1
<?php
2
namespace Xetaravel\Models\Presenters;
3
4
use Xetaravel\Events\Discuss\CategoryWasChangedEvent;
5
use Xetaravel\Events\Discuss\ConversationWasLockedEvent;
6
use Xetaravel\Events\Discuss\ConversationWasPinnedEvent;
7
use Xetaravel\Events\Discuss\PostWasDeletedEvent;
8
use Xetaravel\Events\Discuss\TitleWasChangedEvent;
9
use Xetaravel\Models\DiscussCategory;
10
use Xetaravel\Models\User;
11
12
trait DiscussLogPresenter
13
{
14
    /**
15
     * Get the type related to the Event.
16
     *
17
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
18
     */
19
    public function getTypeAttribute()
20
    {
21
        switch ($this->event_type) {
0 ignored issues
show
Bug introduced by
The property event_type 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...
22
            case CategoryWasChangedEvent::class:
23
                return 'category';
24
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
25
            case TitleWasChangedEvent::class:
26
                return 'title';
27
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
28
            case ConversationWasLockedEvent::class:
29
                return 'locked';
30
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
31
            case ConversationWasPinnedEvent::class:
32
                return 'pinned';
33
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
34
            case PostWasDeletedEvent::class:
35
                return 'deleted';
36
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
37
            default:
38
                return 'unknown';
39
        }
40
    }
41
42
    /**
43
     * Get the user related to the deleted post.
44
     *
45
     * @return null|\Xetaravel\Models\User
46
     */
47
    public function getPostUserAttribute()
48
    {
49
        if ($this->event_type !== PostWasDeletedEvent::class) {
50
            return null;
51
        }
52
53
        return User::find($this->data['post_user_id']);
0 ignored issues
show
Bug introduced by
The property data 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...
54
    }
55
56
    /**
57
     * Get the old category.
58
     *
59
     * @return null|\Xetaravel\Models\DiscussCategory
60
     */
61 View Code Duplication
    public function getOldCategoryAttribute()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        if ($this->event_type !== CategoryWasChangedEvent::class) {
64
            return null;
65
        }
66
67
        return DiscussCategory::find($this->data['old']);
68
    }
69
70
    /**
71
     * Get the new category.
72
     *
73
     * @return null|\Xetaravel\Models\DiscussCategory
74
     */
75 View Code Duplication
    public function getNewCategoryAttribute()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        if ($this->event_type !== CategoryWasChangedEvent::class) {
78
            return null;
79
        }
80
81
        return DiscussCategory::find($this->data['new']);
82
    }
83
}
84