FootersController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 7
dl 0
loc 139
ccs 0
cts 75
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A show() 0 11 1
A index() 0 11 1
A create() 0 12 1
A store() 0 12 1
A edit() 0 14 1
A update() 0 12 1
A delete() 0 10 1
A transNotification() 0 10 1
1
<?php namespace Arcanesoft\Seo\Http\Controllers\Admin;
2
3
use Arcanesoft\Seo\Entities\Locales;
4
use Arcanesoft\Seo\Http\Requests\Admin\Footers\CreateFooterRequest;
5
use Arcanesoft\Seo\Http\Requests\Admin\Footers\UpdateFooterRequest;
6
use Arcanesoft\Seo\Models\Footer;
7
use Arcanesoft\Seo\Models\Page;
8
use Arcanesoft\Seo\Policies;
9
use Illuminate\Support\Facades\Log;
10
11
/**
12
 * Class     FootersController
13
 *
14
 * @package  Arcanesoft\Seo\Http\Controllers\Admin
15
 * @author   ARCANEDEV <[email protected]>
16
 */
17
class FootersController extends Controller
18
{
19
    /* -----------------------------------------------------------------
20
     |  Constructor
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * FootersController constructor.
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct();
30
31
        $this->setCurrentPage('seo-footers');
32
        $this->addBreadcrumbRoute(trans('seo::footers.titles.footers'), 'admin::seo.footers.index');
33
    }
34
35
    /* -----------------------------------------------------------------
36
     |  Main Methods
37
     | -----------------------------------------------------------------
38
     */
39
40
    public function index()
41
    {
42
        $this->authorize(Policies\FootersPolicy::PERMISSION_LIST);
43
44
        $footers = Footer::with(['page', 'seo'])->paginate(50);
0 ignored issues
show
Bug introduced by
The method paginate does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
45
46
        $this->setTitle($title = trans('seo::footers.titles.footers-list'));
47
        $this->addBreadcrumb($title);
48
49
        return $this->view('admin.footers.index', compact('footers'));
50
    }
51
52
    public function create()
53
    {
54
        $this->authorize(Policies\FootersPolicy::PERMISSION_CREATE);
55
56
        $pages   = Page::getSelectData();
57
        $locales = Locales::all();
58
59
        $this->setTitle($title = trans('seo::footers.titles.new-footer'));
60
        $this->addBreadcrumb($title);
61
62
        return $this->view('admin.footers.create', compact('pages', 'locales'));
63
    }
64
65
    public function store(CreateFooterRequest $request)
66
    {
67
        $this->authorize(Policies\FootersPolicy::PERMISSION_CREATE);
68
69
        $footer = Footer::createOne(
70
            $request->getValidatedData()
71
        );
72
73
        $this->transNotification('created', ['name' => $footer->name], $footer->toArray());
74
75
        return redirect()->route('admin::seo.footers.show', [$footer]);
76
    }
77
78
    public function show(Footer $footer)
79
    {
80
        $this->authorize(Policies\FootersPolicy::PERMISSION_SHOW);
81
82
        $footer->load(['page', 'seo']);
83
84
        $this->setTitle($title = trans('seo::footers.titles.footer-details'));
85
        $this->addBreadcrumb($title);
86
87
        return $this->view('admin.footers.show', compact('footer'));
88
    }
89
90
    public function edit(Footer $footer)
91
    {
92
        $this->authorize(Policies\FootersPolicy::PERMISSION_UPDATE);
93
94
        $footer->load(['page', 'seo']);
95
96
        $pages   = Page::getSelectData();
97
        $locales = Locales::all();
98
99
        $this->setTitle($title = trans('seo::footers.titles.edit-footer'));
100
        $this->addBreadcrumb($title);
101
102
        return $this->view('admin.footers.edit', compact('footer', 'pages', 'locales'));
103
    }
104
105
    public function update(Footer $footer, UpdateFooterRequest $request)
106
    {
107
        $this->authorize(Policies\FootersPolicy::PERMISSION_UPDATE);
108
109
        $footer->updateOne(
110
            $request->getValidatedData()
111
        );
112
113
        $this->transNotification('updated', ['name' => $footer->name], $footer->toArray());
114
115
        return redirect()->route('admin::seo.footers.show', [$footer]);
116
    }
117
118
    public function delete(Footer $footer)
119
    {
120
        $this->authorize(Policies\FootersPolicy::PERMISSION_DELETE);
121
122
        $footer->delete();
123
124
        return $this->jsonResponseSuccess([
125
            'message' => $this->transNotification('deleted', ['name' => $footer->name], $footer->toArray())
126
        ]);
127
    }
128
129
    /* -----------------------------------------------------------------
130
     |  Other Methods
131
     | -----------------------------------------------------------------
132
     */
133
134
    /**
135
     * Notify with translation.
136
     *
137
     * @todo: Refactor this method to the core package ?
138
     *
139
     * @param  string  $action
140
     * @param  array   $replace
141
     * @param  array   $context
142
     *
143
     * @return string
144
     */
145
    protected function transNotification($action, array $replace = [], array $context = [])
146
    {
147
        $title   = trans("seo::footers.messages.{$action}.title");
148
        $message = trans("seo::footers.messages.{$action}.message", $replace);
149
150
        Log::info($message, $context);
151
        $this->notifySuccess($message, $title);
152
153
        return $message;
154
    }
155
}
156