GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 13526a...f52031 )
by Toby
14:25 queued 11s
created

File::scopeWithTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 8
nc 1
nop 2
dl 0
loc 11
c 0
b 0
f 0
cc 1
rs 10
ccs 8
cts 8
cp 1
crap 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\Module\UploadFile\Models;
4
5
use BristolSU\Support\ActivityInstance\ActivityInstance;
6
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceRepository;
7
use BristolSU\Support\Authentication\HasResource;
8
use BristolSU\ControlDB\Contracts\Repositories\User as UserRepository;
9
use BristolSU\Support\ModuleInstance\Contracts\ModuleInstanceRepository;
10
use BristolSU\Support\ModuleInstance\ModuleInstance;
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Database\Eloquent\SoftDeletes;
13
use Illuminate\Database\Eloquent\Builder;
14
use Illuminate\Support\Facades\Config;
15
16
class File extends Model
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class File
Loading history...
17
{
18
    use SoftDeletes, HasResource;
19
20
    protected $table = 'uploadfile_files';
21
    
22
    protected $appends = ['status'];
23
    
24
    protected $fillable = [
25
        'title',
26
        'description',
27
        'filename',
28
        'mime',
29
        'path',
30
        'size',
31
        'uploaded_by',
32
        'module_instance_id',
33
        'activity_instance_id',
34
        'tags'
35
    ];
36
    
37
    protected $casts = [
38
        'tags' => 'array'
39
    ];
40
41 70
    public function getUploadedByAttribute($uploadedById)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getUploadedByAttribute()
Loading history...
42
    {
43 70
        return app()->make(UserRepository::class)->getById($uploadedById);
44
    }
45
46 2
    public function scopeWithTag(Builder $query, string $tag)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function scopeWithTag()
Loading history...
47
    {
48 2
        $activityInstanceRepository = app(ActivityInstanceRepository::class);
49 2
        $activityInstance = $activityInstanceRepository->getById(static::activityInstanceId());
50
        $activityInstanceIds = $activityInstanceRepository
51 2
            ->allForResource($activityInstance->resource_type, $activityInstance->resource_id)
52
            ->map(function(ActivityInstance $activityInstance) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
53 2
                return $activityInstance->id;
54 2
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
55 2
        return $query->whereIn('activity_instance_id', $activityInstanceIds->toArray())
56 2
            ->where('tags', 'LIKE', '%"' . $tag . '"%');
57
    }   
58
    
59
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
60
     * @return ModuleInstance
61
     */
62 61
    public function moduleInstance()
63
    {
64 61
        return app(ModuleInstanceRepository::class)->getById($this->module_instance_id);
65
    }
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @return ActivityInstance
69
     */
70 2
    public function activityInstance()
71
    {
72 2
        return app(ActivityInstanceRepository::class)->getById($this->activity_instance_id);
73
    }
74
75 74
    public function statuses()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function statuses()
Loading history...
76
    {
77 74
        return $this->hasMany(FileStatus::class);
78
    }
79
80 69
    public function getStatusAttribute()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getStatusAttribute()
Loading history...
81
    {
82 69
        if($this->statuses()->count() > 0) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
83 9
            return $this->statuses()->latest('created_at')->first()->status;
84
        }
85
        
86 60
        $statuses = Config::get('uploadfile.statuses');
87 60
        if(!is_array($statuses) || count($statuses) === 0) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
88 2
            $default = 'Awaiting Approval';
89
        } else {
90 58
            $default = $statuses[0];
91
        }
92
        
93 60
        return $this->moduleInstance()->setting('initial_status', $default);
94
    }
95
96 18
    public function comments()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function comments()
Loading history...
97
    {
98 18
        return $this->hasMany(Comment::class);
99
    }
100
101
}