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 — laravel-8 ( 5f420c )
by Toby
15:16
created

File::serializeDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
    /**
42
     * Prepare a date for array / JSON serialization.
43
     *
44
     * @param  \DateTimeInterface  $date
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
45
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
46
     */
47 55
    protected function serializeDate(\DateTimeInterface $date)   
48
    {
49 55
        return $date->format('Y-m-d H:i:s');
50
    }
51
52
53 70
    public function getUploadedByAttribute($uploadedById)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getUploadedByAttribute()
Loading history...
54
    {
55 70
        return app()->make(UserRepository::class)->getById($uploadedById);
56
    }
57
58 2
    public function scopeWithTag(Builder $query, string $tag)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function scopeWithTag()
Loading history...
59
    {
60 2
        $activityInstanceRepository = app(ActivityInstanceRepository::class);
61 2
        $activityInstance = $activityInstanceRepository->getById(static::activityInstanceId());
62
        $activityInstanceIds = $activityInstanceRepository
63 2
            ->allForResource($activityInstance->resource_type, $activityInstance->resource_id)
64 2
            ->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...
65 2
                return $activityInstance->id;
66 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...
67 2
        return $query->whereIn('activity_instance_id', $activityInstanceIds->toArray())
68 2
            ->where('tags', 'LIKE', '%"' . $tag . '"%');
69
    }   
70
    
71
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
72
     * @return ModuleInstance
73
     */
74 61
    public function moduleInstance()
75
    {
76 61
        return app(ModuleInstanceRepository::class)->getById($this->module_instance_id);
77
    }
78
79
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
80
     * @return ActivityInstance
81
     */
82 6
    public function activityInstance()
83
    {
84 6
        return app(ActivityInstanceRepository::class)->getById($this->activity_instance_id);
85
    }
86
87 74
    public function statuses()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function statuses()
Loading history...
88
    {
89 74
        return $this->hasMany(FileStatus::class);
90
    }
91
92 69
    public function getStatusAttribute()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getStatusAttribute()
Loading history...
93
    {
94 69
        if($this->statuses()->count() > 0) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
95 9
            return $this->statuses()->latest('created_at')->first()->status;
96
        }
97
        
98 60
        $statuses = Config::get('uploadfile.statuses');
99 60
        if(!is_array($statuses) || count($statuses) === 0) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
100 2
            $default = 'Awaiting Approval';
101
        } else {
102 58
            $default = $statuses[0];
103
        }
104
        
105 60
        return $this->moduleInstance()->setting('initial_status', $default);
106
    }
107
108 18
    public function comments()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function comments()
Loading history...
109
    {
110 18
        return $this->hasMany(Comment::class);
111
    }
112
113
}
114