ProfileController::update()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pratiksh\Adminetic\Http\Controllers\Admin;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller 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...
6
use Pratiksh\Adminetic\Contracts\ProfileRepositoryInterface;
7
use Pratiksh\Adminetic\Http\Requests\ProfileRequest;
8
use Pratiksh\Adminetic\Models\Admin\Profile;
9
10
class ProfileController extends Controller
11
{
12
    protected $profileRepositoryInterface;
13
14
    public function __construct(ProfileRepositoryInterface $profileRepositoryInterface)
15
    {
16
        $this->profileRepositoryInterface = $profileRepositoryInterface;
17
    }
18
19
    /**
20
     * Display the specified resource.
21
     *
22
     * @param  \Pratiksh\Adminetic\Models\Admin\Profile  $profile
23
     * @return \Illuminate\Http\Response
24
     */
25
    public function show(Profile $profile)
26
    {
27
        return $this->checkAuthorization($profile) ? view('adminetic::admin.profile.show', $this->profileRepositoryInterface->showProfile($profile)) : abort(403);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->checkAutho...$profile)) : abort(403) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Bug introduced by
Are you sure the usage of abort(403) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
28
    }
29
30
    /**
31
     * Show the form for editing the specified resource.
32
     *
33
     * @param  \Pratiksh\Adminetic\Models\Admin\Profile  $profile
34
     * @return \Illuminate\Http\Response
35
     */
36
    public function edit(Profile $profile)
37
    {
38
        return $this->checkAuthorization($profile) ? view('adminetic::admin.profile.edit', $this->profileRepositoryInterface->editProfile($profile)) : abort(403);
0 ignored issues
show
Bug introduced by
Are you sure the usage of abort(403) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug Best Practice introduced by
The expression return $this->checkAutho...$profile)) : abort(403) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
39
    }
40
41
    /**
42
     * Update the specified resource in storage.
43
     *
44
     * @param  \Pratiksh\Adminetic\Http\Requests\ProfileRequest  $request
45
     * @param  \Pratiksh\Adminetic\Models\Admin\Profile  $profile
46
     * @return \Illuminate\Http\Response
47
     */
48
    public function update(ProfileRequest $request, Profile $profile)
49
    {
50
        if ($this->checkAuthorization($profile)) {
51
            $this->profileRepositoryInterface->updateProfile($request, $profile);
52
53
            return redirect(adminEditRoute('profile', $profile->id))->withInfo('Profile Updated Sucessfully');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect(adminEdi...e Updated Sucessfully') also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
54
        } else {
55
            return abort(403);
0 ignored issues
show
Bug Best Practice introduced by
The expression return abort(403) returns the type void which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Bug introduced by
Are you sure the usage of abort(403) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
56
        }
57
    }
58
59
    /**
60
     * Check Authorization.
61
     */
62
    protected function checkAuthorization(Profile $profile)
63
    {
64
        return auth()->user()->hasRole('superadmin') || auth()->user()->hasRole('admin') || auth()->user()->id == $profile->user_id;
65
    }
66
}
67