Passed
Push — 5.0.0 ( 337324...37581b )
by Fèvre
05:07
created

CommentController::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 1
dl 0
loc 25
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Controllers\Blog;
6
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Illuminate\Http\RedirectResponse;
9
use Illuminate\Http\Request;
10
use Xetaravel\Http\Controllers\Controller;
11
use Xetaravel\Models\BlogComment;
12
13
class CommentController extends Controller
14
{
15
    /**
16
     * Redirect a user to an article, page and comment.
17
     *
18
     * @param Request $request
19
     * @param int $id The ID of the comment.
20
     *
21
     * @return RedirectResponse
22
     *
23
     * @throws ModelNotFoundException
24
     */
25
    public function show(Request $request, int $id): RedirectResponse
26
    {
27
        $comment = BlogComment::findOrFail($id);
28
29
        $commentsBefore = BlogComment::where([
30
            ['blog_article_id', $comment->blog_article_id],
0 ignored issues
show
Bug introduced by
The property blog_article_id does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
31
            ['created_at', '>', $comment->created_at]
0 ignored issues
show
Bug introduced by
The property created_at does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
32
        ])->count();
33
34
        $commentsPerPage = config('xetaravel.pagination.blog.comment_per_page');
35
36
        $page = floor($commentsBefore / $commentsPerPage) + 1;
37
        $page = ($page > 1) ? $page : 1;
38
39
        $request->session()->keep(['primary', 'error', 'warning', 'success', 'info']);
40
41
        return redirect()
42
            ->route(
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

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

42
            ->/** @scrutinizer ignore-call */ route(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
                'blog.article.show',
44
                [
45
                    'slug' => $comment->article->slug,
0 ignored issues
show
Bug introduced by
The property article does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
46
                    'id' => $comment->article->id,
47
                    'page' => $page,
48
                    '#comment-' . $comment->getKey()
49
                ]
50
            );
51
    }
52
}
53