StreamPresenter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 79
loc 79
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A labels() 11 11 1
A translatableLabel() 10 10 2
A trashableLabel() 10 10 2
A sortableLabel() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Anomaly\Streams\Platform\Stream;
2
3
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface;
4
use Anomaly\Streams\Platform\Support\Presenter;
5
6
/**
7
 * Class StreamPresenter
8
 *
9
 * @link   http://pyrocms.com/
10
 * @author PyroCMS, Inc. <[email protected]>
11
 * @author Ryan Thompson <[email protected]>
12
 */
13 View Code Duplication
class StreamPresenter extends Presenter
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
16
    /**
17
     * The stream interface.
18
     *
19
     * @var StreamInterface
20
     */
21
    protected $object;
22
23
    /**
24
     * Return the flag labels.
25
     *
26
     * @param  string $size
27
     * @return string
28
     */
29
    public function labels($size = 'sm')
30
    {
31
        return implode(
32
            ' ',
33
            [
34
                $this->translatableLabel($size),
35
                $this->trashableLabel($size),
36
                $this->sortableLabel($size),
37
            ]
38
        );
39
    }
40
41
    /**
42
     * Return the translatable label.
43
     *
44
     * @param  string $size
45
     * @return null|string
46
     */
47
    protected function translatableLabel($size = 'sm')
48
    {
49
        if ($this->object->isTranslatable()) {
50
            return '<span class="tag tag-info tag-' . $size . '">' . trans(
51
                'streams::field.translatable.name'
52
            ) . '</span>';
53
        }
54
55
        return null;
56
    }
57
58
    /**
59
     * Return the trashable label.
60
     *
61
     * @param  string $size
62
     * @return null|string
63
     */
64
    protected function trashableLabel($size = 'sm')
65
    {
66
        if ($this->object->isTrashable()) {
67
            return '<span class="tag tag-danger tag-' . $size . '">' . trans(
68
                'streams::field.trashable.name'
69
            ) . '</span>';
70
        }
71
72
        return null;
73
    }
74
75
    /**
76
     * Return the sortable label.
77
     *
78
     * @param  string $size
79
     * @return null|string
80
     */
81
    protected function sortableLabel($size = 'sm')
82
    {
83
        if ($this->object->isSortable()) {
84
            return '<span class="tag tag-primary tag-' . $size . '">' . trans(
85
                'streams::field.sortable.name'
86
            ) . '</span>';
87
        }
88
89
        return null;
90
    }
91
}
92