PostPresenter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 9
c 6
b 0
f 0
lcom 2
cbo 2
dl 0
loc 70
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A previous() 0 4 1
A next() 0 4 1
A status() 0 4 1
B statusLabelClass() 0 20 5
1
<?php namespace Modules\Blog\Presenters;
2
3
use Laracasts\Presenter\Presenter;
4
use Modules\Blog\Entities\Status;
5
6
class PostPresenter extends Presenter
7
{
8
    /**
9
     * @var \Modules\Blog\Entities\Status
10
     */
11
    protected $status;
12
    /**
13
     * @var \Modules\Blog\Repositories\PostRepository
14
     */
15
    private $post;
16
17
    public function __construct($entity)
18
    {
19
        parent::__construct($entity);
20
        $this->post = app('Modules\Blog\Repositories\PostRepository');
21
        $this->status = app('Modules\Blog\Entities\Status');
22
    }
23
24
    /**
25
     * Get the previous post of the current post
26
     * @return object
27
     */
28
    public function previous()
29
    {
30
        return $this->post->getPreviousOf($this->entity);
31
    }
32
33
    /**
34
     * Get the next post of the current post
35
     * @return object
36
     */
37
    public function next()
38
    {
39
        return $this->post->getNextOf($this->entity);
40
    }
41
42
    /**
43
     * Get the post status
44
     * @return string
45
     */
46
    public function status()
47
    {
48
        return $this->status->get($this->entity->status);
49
    }
50
51
    /**
52
     * Getting the label class for the appropriate status
53
     * @return string
54
     */
55
    public function statusLabelClass()
56
    {
57
        switch ($this->entity->status) {
58
            case Status::DRAFT:
59
                return 'bg-red';
60
                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...
61
            case Status::PENDING:
62
                return 'bg-orange';
63
                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...
64
            case Status::PUBLISHED:
65
                return 'bg-green';
66
                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...
67
            case Status::UNPUBLISHED:
68
                return 'bg-purple';
69
                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...
70
            default:
71
                return 'bg-red';
72
                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...
73
        }
74
    }
75
}
76