Completed
Push — master ( db6658...fecd46 )
by Eric
01:44
created

StoreArticle::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace Ergare17\Articles\Http\Requests;
4
5
use Acacha\Events\Http\Requests\Traits\ChecksPermissions;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Illuminate\Support\Facades\Auth;
8
9
/**
10
 * Class StoreArticle
11
 *
12
 * @package App\Http\Requests
13
 */
14
class StoreArticle extends FormRequest
15
{
16
    use ChecksPermissions;
17
18
    /**
19
     * Determine if the user is authorized to make this request.
20
     *
21
     * @return bool
22
     */
23
    public function authorize()
24
    {
25
        if ($this->hasPermissionTo('store-article')) return true;
26
        if (Auth::user()->id === $this->user_id) return true;
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...
27
        return false;
28
    }
29
30
    /**
31
     * Get the validation rules that apply to the request.
32
     *
33
     * @return array
34
     */
35
    public function rules()
36
    {
37
        return [
38
            'name' => 'required',
39
            'user_id' => 'required'
40
        ];
41
    }
42
}
43