PostPresenter::renderTitle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace App\Libraries\Presenterable\Presenters;
4
5
use App\Traits\HasImagesPresentable;
6
use Jenssegers\Date\Date;
7
8
class PostPresenter extends Presenter
9
{
10
    use HasImagesPresentable;
11
12
    /**
13
     * Render short description from post's body.
14
     *
15
     * @param $range
16
     * @return string
17
     */
18
    public function renderShortDescription($range = 75)
19
    {
20
        return sprintf('%s... </p>', substr($this->model->body, 0, $range));
21
    }
22
23
    /**
24
     * Render post title.
25
     *
26
     * @return string
27
     */
28
    public function renderTitle($upper = false)
29
    {
30
        $name = $this->model->title;
31
32
        if($upper)
33
            return strtoupper($name);
34
35
        return ucfirst($name);
36
    }
37
38
    /**
39
     * Render published date from created_at.
40
     *
41
     * @param string
42
     * @return string
43
     */
44
    public function renderPublishedDate($format = 'd F Y')
45
    {
46
        Date::setLocale(\Lang::slug());
47
48
        $date = Date::createFromTimestamp(
49
            $this->model->created_at->timestamp
50
        );
51
52
        return $date->format($format);
53
    }
54
55
    /**
56
     * Render post's views.
57
     *
58
     * @return string
59
     */
60
    public function renderPostViews()
61
    {
62
        return $this->model->view_count;
63
    }
64
}