Test Setup Failed
Pull Request — master (#107)
by Glenn
23:00 queued 16:14
created

StaffController::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 22
rs 9.2
cc 2
eloc 15
nc 2
nop 1
1
<?php
2
3
namespace app\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Http\Requests;
7
use App\User;
8
use App\Countries;
9
use App\Departments;
10
use App\Teams;
11
use App\Role;
12
use Illuminate\Support\Facades\Auth;
13
use Illuminate\Support\Facades\Input;
14
use Illuminate\Support\Facades\Mail;
15
use Illuminate\Support\Facades\Redirect;
16
use Intervention\Image\Facades\Image;
17
use App\Permission;
18
use Bouncer;
19
use App\Http\Controllers\Controller;
20
21
class StaffController extends Controller
22
{
23
    /**
24
     * StaffController constructor.
25
     */ 
26
    public function __construct()
27
    {
28
        $this->middleware('auth');
29
        $this->middleware('lang');
30
    }
31
32
    /**
33
     * Display all users.
34
     *
35
     * @return mixed
36
     */
37
    public function index()
38
    {
39
        $data['users'] = User::orderBy('fname', 'asc')->paginate(10);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
40
41
        return view('staff/users', $data);
42
    }
43
44
    /**
45
     * Show the form for creating a new employee.
46
     *
47
     * @return mixed
48
     */
49
    public function create()
50
    {
51
        $data['countries'] = Countries::all();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
52
53
        return view('staff/create_user', $data);
54
    }
55
56
    /**
57
     * Store a newly created employee in storage.
58
     *
59
     * @param Requests\StaffValidator|Request $request
60
     *
61
     * @return mixed
62
     */
63
    public function store(Requests\StaffValidator $request)
64
    {
65
        $user = new User();
66
        $user->fname = $request->get('fname');
0 ignored issues
show
Documentation introduced by
The property fname does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
67
        $user->name = $request->get('name');
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
        $user->address = $request->get('address');
0 ignored issues
show
Documentation introduced by
The property address does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
69
        $user->postal_code = $request->get('postal_code');
0 ignored issues
show
Documentation introduced by
The property postal_code does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
70
        $user->city = $request->get('city');
0 ignored issues
show
Documentation introduced by
The property city does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
71
        $user->email = $request->get('email');
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
72
        $user->password = bcrypt($request->get('password'));
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
73
        $user->save();
74
75
        $mailbox = env('MAIL_USERNAME');
76
        $mail_password = $request->get('password');
77
        session()->flash('message', 'New employee has been added to the application');
78
79
        $injectionData = ['user' => $user, 'password' => $mail_password];
80
81
        Mail::send('emails.new_user', $injectionData, function ($m) use ($user, $mailbox) {
82
            $m->from($mailbox);
83
            $m->to($user->email)->subject('Your user credentials!');
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
84
        });
85
86
        return redirect('staff');
87
    }
88
89
    /**
90
     * Update a user.
91
     *
92
     * @param Int,    $id
0 ignored issues
show
Documentation introduced by
The doc-type Int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
93
     * @param Request $request
94
     *
95
     * @return mixed
96
     */
97
    public function updateUser($id, Request $request)
98
    {
99
        $user = User::find($id);
100
        $user->fname = $request->get('fname');
101
        $user->name = $request->get('name');
102
        $user->address = $request->get('address');
103
        $user->postal_code = $request->get('postal_code');
104
        $user->city = $request->get('city');
105
        $user->email = $request->get('email');
106
        $user->assignRole($request->get('user_type'));
107
        $user->update();
108
109
        $user = User::find($id);
110
        Bouncer::assign($request->get('user_typ'))->to($user);
111
112
        session()->flash('message', 'User details have been updated');
113
114
        return \Redirect::back();
115
    }
116
117
    /**
118
     * @return mixed
119
     */
120
    public function policies()
121
    {
122
        $data['roles'] = Role::all();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
123
124
        return view('staff/roles', $data);
125
    }
126
127
    /**
128
     * @return mixed
129
     */
130
    public function addpolicies()
131
    {
132
        $data['permissions'] = Permission::all();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
133
134
        return view('staff/create_role', $data);
135
    }
136
137
    /**
138
     * @param Request $request
139
     *
140
     * @return string
141
     */
142
    public function addRole(Request $request)
143
    {
144
        $role = Role::create(['name' => $request->get('role_name')]);
145
        foreach ($request->get('permissions') as $permission) {
146
            $role->givePermissionTo($permission);
0 ignored issues
show
Documentation Bug introduced by
The method givePermissionTo does not exist on object<App\Role>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
147
        }
148
        if ($assign_role) {
0 ignored issues
show
Bug introduced by
The variable $assign_role does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
149
            session()->flash('message', 'New user role has been created');
150
151
            return redirect('staff/policies');
152
        } else {
153
            return 'Mislukt';
154
        }
155
    }
156
157
    /**
158
     * @param $id
159
     *
160
     * @return mixed
161
     */
162
    public function editpolicies($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
163
    {
164
        $data['permissions'] = Permission::all();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
165
166
        return view('staff/edit_role', $data);
167
    }
168
169
    /**
170
     * Remove the user role.
171
     *
172
     * @param int, $id
0 ignored issues
show
Documentation introduced by
The doc-type int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
173
     *
174
     * @return redirect
175
     */
176
    public function destroyRole($id)
177
    {
178
        $role = Role::find($id);
179
        $role->delete();
180
        session()->flash('message', 'User role has been removed from the database');
181
182
        return redirect('staff/policies');
183
    }
184
185
    /**
186
     * Show all permission.
187
     */
188
    public function permissions()
189
    {
190
        $data['permissions'] = Permission::all();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
191
192
        return view('staff/permissions', $data);
193
    }
194
195
    /**
196
     * Show the form to create a new permission.
197
     */
198
    public function createPermission()
199
    {
200
        return view('staff/create_permission');
201
    }
202
203
    /**
204
     * Show the form to edit a permission.
205
     */
206
    public function EditPermission(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
207
    {
208
        $data['permission'] = Permission::find($id);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
209
        return view('staff/edit_permission', $data);
210
    }
211
212
    /**
213
     * Save the new permission.
214
     *
215
     * @param Request $request
216
     *
217
     * @return redirect
218
     */
219
    public function savePermission(Request $request)
220
    {
221
        Permission::create(['name' => $request->get('permission_name')]);
222
        session()->flash('message', 'The new permission has been added to the database');
223
224
        return redirect('staff/permissions');
225
    }
226
227
    public function destroyPermission($id)
228
    {
229
        $permission = Permission::find($id);
230
        $permission->delete();
231
232
        session()->flash('message', 'Permission has been removed from the database');
233
234
        return redirect('staff/permissions');
235
    }
236
237
    /**
238
     * Display the specified resource.
239
     *
240
     * @param int $id
241
     *
242
     * @return \Illuminate\Http\Response
243
     */
244
    public function show($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
245
    {
246
        //
247
    }
248
249
    /**
250
     * Show the form for editing the specified resource.
251
     *
252
     * @param $id
253
     *
254
     * @return
255
     */
256
    public function edit($id)
257
    {
258
        $data['user']  = User::findOrFail($id);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
259
        $data['departments'] = Departments::all();
260
        $data['teams'] = Teams::all();
261
        $data['countries'] = Countries::all();
262
        $data['roles'] = Role::all();
263
264
        return view('staff/edit_user', $data);
265
    }
266
267
    /**
268
     * @return mixed
269
     */
270
    public function profile()
271
    {
272
        $data['countries'] = Countries::all();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
273
274
        return view('staff/profile', $data);
275
    }
276
277
    /**
278
     * change a password.
279
     */
280
    public function chPass()
281
    {
282
    }
283
284
    /**
285
     * Update the specified resource in storage.
286
     *
287
     * @param Requests\accountManagementValidator|Request $request
288
     * @return \Illuminate\Http\Response
289
     */
290
    public function update(Requests\accountManagementValidator $request)
291
    {
292
        $user = User::findOrFail(auth()->user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
293
        $user->fname = $request->get('email');
294
        $user->name = $request->get('name');
295
        $user->email = $request->get('email');
296
        $user->address = $request->get('address');
297
        $user->email = $request->get('email');
298
299
        if (Input::file()) {
300
            $image = Input::file('avatar');
301
            $filename = time().'.'.$image->getClientOriginalExtension();
302
            $path = public_path('profilepics/'.$filename);
303
304
            Image::make($image->getRealPath())->resize(200, 200)->save($path);
305
            $user->image = $filename;
306
        }
307
308
        $user->save();
309
310
        return redirect()->back();
311
    }
312
313
    /**
314
     * Remove the specified employee from the database.
315
     *
316
     * @param int $id
317
     *
318
     * @return \Illuminate\Http\Response
319
     */
320
    public function destroy($id)
321
    {
322
        if (!Auth::user()->is('Administrator')) {
323
            return Redirect::back();
324
        }
325
326
        User::Destroy($id);
327
        session()->flash('message', 'User has been removed from the database');
328
329
        return redirect('staff');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect('staff'); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by app\Http\Controllers\StaffController::destroy of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
330
    }
331
}
332