Completed
Pull Request — master (#34)
by Fèvre
19:42 queued 16:30
created

DiscussLogPresenter::getTypeAttribute()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 16
nc 5
nop 0
1
<?php
2
namespace Xetaravel\Models\Presenters;
3
4
use Xetaravel\Events\Discuss\ThreadTitleWasChangedEvent;
5
use Xetaravel\Events\Discuss\ThreadCategoryWasChangedEvent;
6
use Xetaravel\Events\Discuss\ThreadWasLockedEvent;
7
use Xetaravel\Events\Discuss\ThreadWasPinnedEvent;
8
use Xetaravel\Models\DiscussCategory;
9
10
trait DiscussLogPresenter
11
{
12
    /**
13
     * Get the type related to the Event.
14
     *
15
     * @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...
16
     */
17
    public function getTypeAttribute()
18
    {
19
        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...
20
            case ThreadCategoryWasChangedEvent::class:
21
                return 'category';
22
                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...
23
            case ThreadTitleWasChangedEvent::class:
24
                return 'title';
25
                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...
26
            case ThreadWasLockedEvent::class:
27
                return 'locked';
28
                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...
29
            case ThreadWasPinnedEvent::class:
30
                return 'pinned';
31
                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...
32
            default:
33
                return 'unknown';
34
        }
35
    }
36
37
    /**
38
     * Get the old category.
39
     *
40
     * @return \Xetaravel\Models\DiscussCategory
41
     */
42 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...
43
    {
44
        if ($this->event_type !== ThreadCategoryWasChangedEvent::class) {
45
            return null;
46
        }
47
48
        return DiscussCategory::find($this->data['old']);
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...
49
    }
50
51
    /**
52
     * Get the new category.
53
     *
54
     * @return \Xetaravel\Models\DiscussCategory
55
     */
56 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...
57
    {
58
        if ($this->event_type !== ThreadCategoryWasChangedEvent::class) {
59
            return null;
60
        }
61
62
        return DiscussCategory::find($this->data['new']);
63
    }
64
}
65