ArticlePresenter   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A editLink() 0 4 1
A dateCreated() 0 4 1
A published() 0 7 3
A author() 0 6 2
A content() 0 6 2
A datePublished() 0 4 1
A dateModified() 0 4 1
A slug() 0 4 1
A title() 0 9 3
1
<?php
2
3
namespace Yajra\CMS\Presenters;
4
5
use Carbon\Carbon;
6
use Laracasts\Presenter\Presenter;
7
8
class ArticlePresenter extends Presenter
9
{
10
    /**
11
     * Edit link of the article.
12
     *
13
     * @return string
14
     */
15
    public function editLink()
16
    {
17
        return html()->linkRoute('administrator.articles.edit', $this->entity->title, $this->entity->id);
18
    }
19
20
    /**
21
     * Date created.
22
     *
23
     * @return string
24
     */
25
    public function dateCreated()
26
    {
27
        return $this->entity->created_at->format('Y-m-d');
28
    }
29
30
    /**
31
     * Date published.
32
     *
33
     * @return mixed
34
     */
35
    public function datePublished()
36
    {
37
        return $this->entity->created_at->diffForHumans();
38
    }
39
40
    /**
41
     * Date modified.
42
     *
43
     * @return mixed
44
     */
45
    public function dateModified()
46
    {
47
        return $this->entity->updated_at->format('d M Y');
48
    }
49
50
    /**
51
     * Publication state.
52
     *
53
     * @return string
54
     */
55
    public function published()
56
    {
57
        $class = $this->entity->published ? 'fa fa-check-circle-o' : 'fa fa-circle-o';
58
        $state = $this->entity->published ? 'Published' : 'Unpublished';
59
60
        return html()->tag('i', '', ["class" => $class, "data-toggle" => "tooltip", "data-title" => $state]);
61
    }
62
63
    /**
64
     * Get article's author name.
65
     *
66
     * @return string
67
     */
68
    public function author()
69
    {
70
        return ! empty($this->entity->author_alias)
71
            ? $this->entity->author_alias
72
            : $this->entity->createdByName;
73
    }
74
75
    /**
76
     * Get the article's content.
77
     *
78
     * @return string
79
     * @throws \Exception
80
     * @throws \Throwable
81
     */
82
    public function content()
83
    {
84
        return $this->entity->blade_template
85
            ? 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...
86
            : $this->entity->body;
87
    }
88
89
    /**
90
     * Get the article's title.
91
     *
92
     * @return mixed
93
     */
94
    public function title()
95
    {
96
        $heading = null;
97
        if (session()->has('active_menu')) {
98
            $heading = session('active_menu')->param('page_heading');
99
        }
100
101
        return $heading ? $heading : $this->entity->title;
102
    }
103
104
    /**
105
     * Get article's slug.
106
     *
107
     * @return string
108
     */
109
    public function slug()
110
    {
111
        return implode('/', explode('.', $this->entity->getRouteName()));
112
    }
113
}
114