Code Duplication    Length = 114-114 lines in 2 locations

app/Presenters/IssuePresenter.php 1 location

@@ 19-132 (lines=114) @@
16
use GrahamCampbell\Markdown\Facades\Markdown;
17
use Jenssegers\Date\Date;
18
19
class IssuePresenter extends AbstractPresenter
20
{
21
    use TimestampsTrait;
22
23
    /**
24
     * Renders the message from Markdown into HTML.
25
     *
26
     * @return string
27
     */
28
    public function formattedMessage()
29
    {
30
        return Markdown::convertToHtml($this->wrappedObject->description);
31
    }
32
33
    /**
34
     * Present diff for humans date time.
35
     *
36
     * @return string
37
     */
38
    public function created_at_diff()
39
    {
40
        return (new Date($this->wrappedObject->created_at))
41
            ->setTimezone($this->setting->get('app_timezone'))
42
            ->diffForHumans();
43
    }
44
45
    /**
46
     * Present formatted date time.
47
     *
48
     * @return string
49
     */
50
    public function created_at_formatted()
51
    {
52
        return ucfirst((new Date($this->wrappedObject->created_at))
53
            ->setTimezone($this->setting->get('app_timezone'))
54
            ->format($this->setting->get('issue_date_format', 'l jS F Y H:i:s')));
55
    }
56
57
    /**
58
     * Formats the created_at time ready to be used by bootstrap-datetimepicker.
59
     *
60
     * @return string
61
     */
62
    public function created_at_datetimepicker()
63
    {
64
        return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->format('d/m/Y H:i');
65
    }
66
67
    /**
68
     * Present formatted date time.
69
     *
70
     * @return string
71
     */
72
    public function created_at_iso()
73
    {
74
        return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String();
75
    }
76
77
    /**
78
     * Returns a formatted timestamp for use within the timeline.
79
     *
80
     * @return string
81
     */
82
    public function timestamp_formatted()
83
    {
84
        return $this->created_at_formatted;
85
    }
86
87
    /**
88
     * Return the iso timestamp for use within the timeline.
89
     *
90
     * @return string
91
     */
92
    public function timestamp_iso()
93
    {
94
        return $this->created_at_iso;
95
    }
96
97
    /**
98
     * Present the status with an icon.
99
     *
100
     * @return string
101
     */
102
    public function icon()
103
    {
104
        switch ($this->wrappedObject->state) {
105
            case 0: // Scheduled
106
                return 'fa fa-calendar';
107
            case 1: // Investigating
108
                return 'fa fa-flag oranges';
109
            case 2: // Identified
110
                return 'fa fa-warning yellows';
111
            case 3: // Watching
112
                return 'fa fa-eye blues';
113
            case 4: // Fixed
114
                return 'fa fa-wrench greens';
115
            default: // Something actually broke, this shouldn't happen.
116
                return '';
117
        }
118
    }
119
120
    /**
121
     * Convert the presenter instance to an array.
122
     *
123
     * @return string[]
124
     */
125
    public function toArray()
126
    {
127
        return array_merge($this->wrappedObject->toArray(), [
128
            'created_at'   => $this->created_at(),
129
            'updated_at'   => $this->updated_at(),
130
        ]);
131
    }
132
}
133

app/Presenters/NotePresenter.php 1 location

@@ 19-132 (lines=114) @@
16
use GrahamCampbell\Markdown\Facades\Markdown;
17
use Jenssegers\Date\Date;
18
19
class NotePresenter extends AbstractPresenter
20
{
21
    use TimestampsTrait;
22
23
    /**
24
     * Renders the message from Markdown into HTML.
25
     *
26
     * @return string
27
     */
28
    public function formattedMessage()
29
    {
30
        return Markdown::convertToHtml($this->wrappedObject->description);
31
    }
32
33
    /**
34
     * Present diff for humans date time.
35
     *
36
     * @return string
37
     */
38
    public function created_at_diff()
39
    {
40
        return (new Date($this->wrappedObject->created_at))
41
            ->setTimezone($this->setting->get('app_timezone'))
42
            ->diffForHumans();
43
    }
44
45
    /**
46
     * Present formatted date time.
47
     *
48
     * @return string
49
     */
50
    public function created_at_formatted()
51
    {
52
        return ucfirst((new Date($this->wrappedObject->created_at))
53
            ->setTimezone($this->setting->get('app_timezone'))
54
            ->format($this->setting->get('issue_date_format', 'l jS F Y H:i:s')));
55
    }
56
57
    /**
58
     * Formats the created_at time ready to be used by bootstrap-datetimepicker.
59
     *
60
     * @return string
61
     */
62
    public function created_at_datetimepicker()
63
    {
64
        return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->format('d/m/Y H:i');
65
    }
66
67
    /**
68
     * Present formatted date time.
69
     *
70
     * @return string
71
     */
72
    public function created_at_iso()
73
    {
74
        return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String();
75
    }
76
77
    /**
78
     * Returns a formatted timestamp for use within the timeline.
79
     *
80
     * @return string
81
     */
82
    public function timestamp_formatted()
83
    {
84
        return $this->created_at_formatted;
85
    }
86
87
    /**
88
     * Return the iso timestamp for use within the timeline.
89
     *
90
     * @return string
91
     */
92
    public function timestamp_iso()
93
    {
94
        return $this->created_at_iso;
95
    }
96
97
    /**
98
     * Present the status with an icon.
99
     *
100
     * @return string
101
     */
102
    public function icon()
103
    {
104
        switch ($this->wrappedObject->state) {
105
            case 0: // Scheduled
106
                return 'fa fa-calendar';
107
            case 1: // Investigating
108
                return 'fa fa-flag oranges';
109
            case 2: // Identified
110
                return 'fa fa-warning yellows';
111
            case 3: // Watching
112
                return 'fa fa-eye blues';
113
            case 4: // Fixed
114
                return 'fa fa-wrench greens';
115
            default: // Something actually broke, this shouldn't happen.
116
                return '';
117
        }
118
    }
119
120
    /**
121
     * Convert the presenter instance to an array.
122
     *
123
     * @return string[]
124
     */
125
    public function toArray()
126
    {
127
        return array_merge($this->wrappedObject->toArray(), [
128
            'created_at'   => $this->created_at(),
129
            'updated_at'   => $this->updated_at(),
130
        ]);
131
    }
132
}
133