Issues (97)

app/Http/Controllers/BlogController.php (8 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Post;
6
use App\Models\Tag;
7
use App\Services\PostProcesses;
8
use Illuminate\Http\Request;
9
10
class BlogController extends Controller
11
{
12
    /**
13
     * Display a listing of the published blog posts.
14
     *
15
     * @return \Illuminate\Http\Response
16
     */
17
    public function index(Request $request)
18
    {
19
        $tag = $request->get('tag');
20
        $service = new PostProcesses($tag);
21
        $data = $service->getResponse();
22
23
        $layout = $tag ? Tag::layout($tag) : 'blog.roll-layouts.home';
24
25
        return view($layout, $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view($layout, $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
26
    }
27
28
    /**
29
     * Display the specified resource.
30
     *
31
     * @param string  $slug
32
     * @param Request $request
33
     *
34
     * @return \Illuminate\Http\Response
35
     */
36
    public function showPost(Request $request, $slug)
37
    {
38
        $user = \Auth::user();
39
40
        // Allow writers to view posts in draft mode and future dates
41
        if ($user && $user->level() > 2) {
0 ignored issues
show
The method level() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        if ($user && $user->/** @scrutinizer ignore-call */ level() > 2) {
Loading history...
42
            $post = Post::with('tags')
43
                            ->bySlug($slug)
44
                            ->firstOrFail();
45
        } else {
46
            $post = Post::with('tags')
47
                            ->bySlug($slug)
48
                            ->publishedTimePast()
49
                            ->isNotDraft()
50
                            ->firstOrFail();
51
        }
52
53
        $tag = $request->get('tag');
54
55
        if ($tag) {
56
            $tag = Tag::whereTag($tag)->firstOrFail();
57
        }
58
59
        $data = compact('post', 'tag', 'slug');
60
61
        return view($post->layout, $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view($post->layout, $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
62
    }
63
64
    /**
65
     * Display a listing of the authors with published content.
66
     *
67
     * @return \Illuminate\Http\Response
68
     */
69
    public function authors(Request $request)
0 ignored issues
show
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

69
    public function authors(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        $authors = Post::activeAuthors()->get();
72
73
        if (!$authors) {
0 ignored issues
show
$authors is of type Illuminate\Database\Eloquent\Collection, thus it always evaluated to true.
Loading history...
74
            $authors = [];
75
        }
76
77
        $data = [
78
            'authors'   => $authors,
79
            'image'     => config('blog.authors_page_image'),
80
        ];
81
82
        return view('blog.pages.authors', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('blog.pages.authors', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
83
    }
84
85
    /**
86
     * Display a listing of an authors published posts.
87
     *
88
     * @return \Illuminate\Http\Response
89
     */
90
    public function author(Request $request, $author)
91
    {
92
        $tag = $request->get('tag');
93
        $posts = Post::postsByAuthors($author)->get();
94
95
        $data = [
96
            'author'    => $author,
97
            'image'     => config('blog.author_page_image'),
98
            'posts'     => $posts,
99
            'tag'       => $tag,
100
        ];
101
102
        return view('blog.pages.author', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('blog.pages.author', $data) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
103
    }
104
105
    /**
106
     * Get the RSS feed.
107
     *
108
     * @param RssFeed $feed
109
     *
110
     * @return \Illuminate\Http\Response
111
     */
112
    public function rss(RssFeed $feed)
0 ignored issues
show
The type App\Http\Controllers\RssFeed was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
113
    {
114
        $rss = $feed->getRSS();
115
116
        return response($rss)->header('Content-type', 'application/rss+xml');
117
    }
118
}
119