CategoryController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 10
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\Http\RedirectResponse;
8
use Illuminate\View\View;
9
use Xetaravel\Http\Controllers\Controller;
10
use Xetaravel\Models\BlogCategory;
11
12
class CategoryController extends Controller
13
{
14
    public function __construct()
15
    {
16
        parent::__construct();
17
18
        $this->breadcrumbs->removeListElementClasses('breadcrumb');
19
        $this->breadcrumbs->addCrumb('<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2" fill="none"' .
20
            ' viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" ' .
21
            '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' .
22
            ' 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" /></svg> Blog', route('blog.article.index'));
23
    }
24
25
    /**
26
     * Show the category by his id.
27
     *
28
     * @return RedirectResponse|View
29
     */
30
    public function show(string $slug, int $id)
0 ignored issues
show
Unused Code introduced by
The parameter $slug 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

30
    public function show(/** @scrutinizer ignore-unused */ string $slug, int $id)

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...
31
    {
32
        $category = BlogCategory::where('id', $id)->first();
33
34
        if (is_null($category)) {
35
            return redirect()
36
                ->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

36
                ->/** @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...
37
                ->error('This category does not exist or has been deleted !');
38
        }
39
40
        $articles = $category->articles()->with('user', 'category')->paginate(config('xetaravel.pagination.blog.article_per_page'));
41
42
        $this->breadcrumbs->addCrumb("Category : " . e($category->title), $category->show_url);
0 ignored issues
show
Bug introduced by
The property show_url does not seem to exist on Xetaravel\Models\BlogCategory. 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...
43
44
        return view(
45
            'Blog.category.show',
46
            ['articles' => $articles, 'category' => $category, 'breadcrumbs' => $this->breadcrumbs]
47
        );
48
    }
49
}
50