Completed
Push — master ( 7a1e6c...8794c3 )
by Arjay
11:28
created

ArticlePresenter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 71
rs 10
wmc 10
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A editLink() 0 4 1
A dateCreated() 0 4 1
A datePublished() 0 4 1
A published() 0 7 3
A author() 0 6 2
A content() 0 6 2
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
     * Publication state.
41
     *
42
     * @return string
43
     */
44
    public function published()
45
    {
46
        $class = $this->entity->published ? 'fa fa-check-circle-o' : 'fa fa-circle-o';
47
        $state = $this->entity->published ? 'Published' : 'Unpublished';
48
49
        return html()->tag('i', '', ["class" => $class, "data-toggle" => "tooltip", "data-title" => $state]);
50
    }
51
52
    /**
53
     * Get article's author name.
54
     *
55
     * @return string
56
     */
57
    public function author()
58
    {
59
        return ! empty($this->entity->author_alias)
60
            ? $this->entity->author_alias
61
            : $this->entity->createdByName;
62
    }
63
64
    /**
65
     * Get the article's content.
66
     *
67
     * @return string
68
     * @throws \Exception
69
     * @throws \Throwable
70
     */
71
    public function content()
72
    {
73
        return $this->entity->blade_template
74
            ? 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...
75
            : $this->entity->body;
76
    }
77
}
78