Issues (364)

app/Traits/CreatedBy.php (5 issues)

1
<?php
2
3
namespace App\Traits;
4
5
use Illuminate\Database\Eloquent\Relations\Relation;
6
use Illuminate\Support\Facades\Config;
7
8
trait CreatedBy
9
{
10
    public static function bootCreatedBy()
11
    {
12
        self::creating(fn ($model) => $model->setCreatedBy());
13
    }
14
15
    public function createdBy(): Relation
16
    {
17
        $userModel = Config::get('auth.providers.users.model');
18
19
        return $this->belongsTo($userModel, 'created_by');
0 ignored issues
show
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        return $this->/** @scrutinizer ignore-call */ belongsTo($userModel, 'created_by');
Loading history...
20
    }
21
22
    public static function bootUpdatedBy()
23
    {
24
        self::creating(fn ($model) => $model->setUpdatedBy());
25
    }
26
27
    public function UpdatedBy(): Relation
28
    {
29
        $userModel = Config::get('auth.providers.users.model');
30
31
        return $this->belongsTo($userModel, 'updated_by');
32
    }
33
34
    private function setCreatedBy($value = 1)
0 ignored issues
show
The parameter $value 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

34
    private function setCreatedBy(/** @scrutinizer ignore-unused */ $value = 1)

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...
35
    {
36
//        if($value==''){
37
//            if (Auth::check()) {
38
//                $this->created_by = Auth::id();
39
//            }
40
//        }else{
41
        $this->created_by = null;
0 ignored issues
show
Bug Best Practice introduced by
The property created_by does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
42
//        }
43
    }
44
45
    private function setUpdatedBy($value = 1)
0 ignored issues
show
The parameter $value 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

45
    private function setUpdatedBy(/** @scrutinizer ignore-unused */ $value = 1)

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...
46
    {
47
//        if($value==''){
48
//            if (Auth::check()) {
49
//                $this->updated_by = Auth::id();
50
//            }
51
//        }else{
52
        $this->updated_by = null;
0 ignored issues
show
Bug Best Practice introduced by
The property updated_by does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
53
//        }
54
    }
55
}
56