Completed
Push — master ( a06757...18d394 )
by ARCANEDEV
04:53
created

src/Models/Presenters/PostPresenter.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Arcanesoft\Blog\Models\Presenters;
2
3
use Illuminate\Support\Collection;
4
use Illuminate\Support\HtmlString;
5
6
/**
7
 * Trait PostPresenter
8
 *
9
 * @package  Arcanesoft\Blog\Models\Presenters
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @property  string                          locale_native
13
 * @property  \Illuminate\Support\HtmlString  content
14
 * @property  string                          status
15
 * @property  string                          status_name
16
 */
17
trait PostPresenter
18
{
19
    /* -----------------------------------------------------------------
20
     |  Accessors
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * Get the locale's native name.
26
     *
27
     * @return string
28
     */
29
    public function getLocaleNativeAttribute()
30
    {
31
        return localization()->getSupportedLocales()->get($this->locale)->native();
0 ignored issues
show
The property locale does not seem to exist. Did you mean locale_native?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
32
    }
33
34
    /**
35
     * Get the content attribute.
36
     *
37
     * @return \Illuminate\Support\HtmlString
38
     */
39
    public function getContentAttribute()
40
    {
41
        return new HtmlString($this->content_html);
0 ignored issues
show
The property content_html does not seem to exist. Did you mean content?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
    }
43
44
    /**
45
     * Get the status attribute.
46
     *
47
     * @return string
48
     */
49
    public function getStatusAttribute()
50
    {
51
        return $this->isDraft() ? self::STATUS_DRAFT : self::STATUS_PUBLISHED;
52
    }
53
54
    /**
55
     * Set the status attribute.
56
     *
57
     * @param  string  $status
58
     *
59
     * @return self
60
     */
61
    public function setStatusAttribute($status)
62
    {
63
        $this->attributes['is_draft'] = ($status === self::STATUS_DRAFT);
0 ignored issues
show
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
64
65
        return $this;
66
    }
67
68
    /**
69
     * Get the status name attribute.
70
     *
71
     * @return string|null
72
     */
73
    public function getStatusNameAttribute()
74
    {
75
        return self::getStatuses()->get(
76
            $this->getStatusAttribute()
77
        );
78
    }
79
80
    /**
81
     * Get the post statuses.
82
     *
83
     * @return \Illuminate\Support\Collection
84
     */
85
    public static function getStatuses()
86
    {
87
        return new Collection(
88
            trans('blog::posts.statuses', [])
89
        );
90
    }
91
92
    /* -----------------------------------------------------------------
93
     |  URL Accessors
94
     | -----------------------------------------------------------------
95
     */
96
97
    /**
98
     * Get the show URL.
99
     *
100
     * @return string
101
     */
102
    public function getShowUrl()
103
    {
104
        return route('admin::blog.posts.show', $this);
105
    }
106
107
    /**
108
     * Get the edit URL.
109
     *
110
     * @return string
111
     */
112
    public function getEditUrl()
113
    {
114
        return route('admin::blog.posts.edit', $this);
115
    }
116
}
117