Completed
Push — master ( 0309f7...e870c7 )
by Arjay
14:45
created

ArticlePresenter::slug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Yajra\CMS\Presenters;
4
5
use Laracasts\Presenter\Presenter;
6
7
class ArticlePresenter extends Presenter
8
{
9
    /**
10
     * Edit link of the article.
11
     *
12
     * @return string
13
     */
14
    public function editLink()
15
    {
16
        return html()->linkRoute('administrator.articles.edit', $this->entity->title, $this->entity->id);
17
    }
18
19
    /**
20
     * Date created.
21
     *
22
     * @return string
23
     */
24
    public function dateCreated()
25
    {
26
        return $this->entity->created_at->format('Y-m-d');
27
    }
28
29
    /**
30
     * Date published.
31
     *
32
     * @return mixed
33
     */
34
    public function datePublished()
35
    {
36
        return $this->entity->created_at->format('d M Y');
37
    }
38
39
    /**
40
     * Date modified.
41
     *
42
     * @return mixed
43
     */
44
    public function dateModified()
45
    {
46
        return $this->entity->updated_at->format('d M Y');
47
    }
48
49
    /**
50
     * Publication state.
51
     *
52
     * @return string
53
     */
54
    public function published()
55
    {
56
        $class = $this->entity->published ? 'fa fa-check-circle-o' : 'fa fa-circle-o';
57
        $state = $this->entity->published ? 'Published' : 'Unpublished';
58
59
        return html()->tag('i', '', ["class" => $class, "data-toggle" => "tooltip", "data-title" => $state]);
60
    }
61
62
    /**
63
     * Get article's author name.
64
     *
65
     * @return string
66
     */
67
    public function author()
68
    {
69
        return ! empty($this->entity->author_alias)
70
            ? $this->entity->author_alias
71
            : $this->entity->createdByName;
72
    }
73
74
    /**
75
     * Get the article's content.
76
     *
77
     * @return string
78
     * @throws \Exception
79
     * @throws \Throwable
80
     */
81
    public function content()
82
    {
83
        return $this->entity->blade_template
84
            ? view($this->entity->blade_template, compact('article', $this->entity))->render()
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
85
            : $this->entity->body;
86
    }
87
88
    /**
89
     * Get the article's title.
90
     *
91
     * @return mixed
92
     */
93
    public function title()
94
    {
95
        $heading = null;
96
        if (session()->has('active_menu')) {
97
            $heading = session('active_menu')->param('page_heading');
98
        }
99
100
        return $heading ? $heading : $this->entity->title;
101
    }
102
103
    /**
104
     * Get article's slug.
105
     *
106
     * @return string
107
     */
108
    public function slug()
109
    {
110
        return implode('/', explode('.', $this->entity->getRouteName()));
111
    }
112
}
113