ArticleController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
dl 0
loc 64
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 7 1
A __construct() 0 9 1
A show() 0 29 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Controllers\Blog;
6
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\Foundation\Application;
10
use Illuminate\Http\RedirectResponse;
11
use Xetaravel\Http\Controllers\Controller;
12
use Xetaravel\Models\BlogArticle;
13
14
class ArticleController extends Controller
15
{
16
    /**
17
     * Constructor.
18
     */
19
    public function __construct()
20
    {
21
        parent::__construct();
22
23
        $this->breadcrumbs->removeListElementClasses('breadcrumb');
24
        $this->breadcrumbs->addCrumb('<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2" fill="none"' .
25
        ' viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" ' .
26
        'stroke-linejoin="round" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2' .
27
        ' 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" /></svg> Blog', route('blog.article.index'));
28
    }
29
30
    /**
31
     * Show the list of all articles.
32
     *
33
     * @return Factory|View|Application|\Illuminate\View\View|object
34
     */
35
    public function index()
36
    {
37
        $articles = BlogArticle::with('category', 'user')
38
            ->orderByDesc('created_at')
39
            ->paginate(config('xetaravel.pagination.blog.article_per_page'));
40
41
        return view('Blog.article.index', ['articles' => $articles, 'breadcrumbs' => $this->breadcrumbs]);
42
    }
43
44
    /**
45
     * Show the article by his id.
46
     *
47
     * @return Application|Factory|RedirectResponse|\Illuminate\View\View|object|View
48
     */
49
    public function show(string $slug, int $id)
50
    {
51
        $article = BlogArticle::with('category', 'user')
52
            ->where('id', $id)
53
            ->first();
54
55
        if (is_null($article)) {
56
            return redirect()
57
                ->route('blog.article.index')
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

57
                ->/** @scrutinizer ignore-call */ route('blog.article.index')

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...
58
                ->error('This article does not exist or has been deleted !');
59
        }
60
61
        $url = urlencode(route('blog.article.show', ['slug' => $article->slug, 'id' => $article->getKey()]));
62
        $title = urlencode($article->title);
63
64
        $shareLinks = [
65
            'facebook' => "https://www.facebook.com/sharer/sharer.php?u={$url}",
66
            'twitter' => "https://x.com/intent/tweet?text={$title}&url={$url}",
67
            'linkedin' => "https://www.linkedin.com/shareArticle?mini=true&url={$url}&title={$title}"
68
        ];
69
70
        $breadcrumbs = $this->breadcrumbs->addCrumb('<svg xmlns="http://www.w3.org/2000/svg" fill="none"' .
71
        ' viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 mr-2"><path ' .
72
        'stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125' .
73
        ' 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621' .
74
        ' 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0' .
75
        ' 00-9-9z" /></svg> Article : ' . e($article->title), $article->show_url);
0 ignored issues
show
Bug introduced by
The property show_url does not seem to exist on Xetaravel\Models\BlogArticle. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
76
77
        return view('Blog.article.show', compact('article', 'breadcrumbs', 'shareLinks'));
78
    }
79
}
80