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.

ModuleServiceProvider::baseDirectory()   A
last analyzed

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
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\Module\UploadFile;
4
5
use BristolSU\Module\UploadFile\CompletionConditions\NumberOfDocumentsSubmitted;
6
use BristolSU\Module\UploadFile\CompletionConditions\NumberOfDocumentsWithStatus;
7
use BristolSU\Module\UploadFile\Events\CommentCreated;
8
use BristolSU\Module\UploadFile\Events\CommentDeleted;
9
use BristolSU\Module\UploadFile\Events\CommentUpdated;
10
use BristolSU\Module\UploadFile\Events\DocumentDeleted;
11
use BristolSU\Module\UploadFile\Events\DocumentUpdated;
12
use BristolSU\Module\UploadFile\Events\DocumentUploaded;
13
use BristolSU\Module\UploadFile\Events\StatusChanged;
14
use BristolSU\Module\UploadFile\Fields\TagList;
15
use BristolSU\Module\UploadFile\Models\Comment;
16
use BristolSU\Module\UploadFile\Models\File;
17
use BristolSU\Module\UploadFile\Models\FileStatus;
18
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceResolver;
19
use BristolSU\Support\Completion\Contracts\CompletionConditionManager;
20
use BristolSU\Support\Module\ModuleServiceProvider as ServiceProvider;
21
use BristolSU\Support\ModuleInstance\ModuleInstance;
22
use FormSchema\Generator\Field;
23
use FormSchema\Generator\Form as FormGenerator;
24
use FormSchema\Generator\Group;
25
use FormSchema\Schema\Form;
26
use Illuminate\Database\Eloquent\ModelNotFoundException;
27
use Illuminate\Support\Facades\Route;
28
29
class ModuleServiceProvider extends ServiceProvider
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ModuleServiceProvider
Loading history...
30
{
31
32
    protected $permissions = [
33
        // ##### Web #####
34
        'view-page' => [
35
            'name' => 'View Participant Page',
36
            'description' => 'View the main page of the module.',
37
            'admin' => false
38
        ],
39
        'admin.view-page' => [
40
            'name' => 'View Admin Page',
41
            'description' => 'View the administrator page of the module.',
42
            'admin' => true
43
        ],
44
        
45
        // ##### Api #####
46
        // Files
47
        'file.store' => [
48
            'name' => 'Upload a new file',
49
            'description' => 'Allow the ability to upload a file.',
50
            'admin' => false
51
        ],
52
        'file.download' => [
53
            'name' => 'Download a file',
54
            'description' => 'Allow the user to download a file',
55
            'admin' => false
56
        ],
57
        'file.index' => [
58
            'name' => 'See files',
59
            'description' => 'Allow the user to view files',
60
            'admin' => false
61
        ],
62
        'file.destroy' => [
63
            'name' => 'Delete files',
64
            'description' => 'Allow the user to delete files',
65
            'admin' => false
66
        ],
67
        'file.update' => [
68
            'name' => 'Edit files',
69
            'description' => 'Allow the user to edit files',
70
            'admin' => false
71
        ],
72
        // Comments
73
        'comment.index' => [
74
            'name' => 'See comments',
75
            'description' => 'Allow the user to see comments',
76
            'admin' => false
77
        ],
78
        'comment.store' => [
79
            'name' => 'Comment',
80
            'description' => 'Allow the user to comment in files',
81
            'admin' => false
82
        ],
83
        'comment.destroy' => [
84
            'name' => 'Delete a Comment',
85
            'description' => 'Allow the user to delete a comment.',
86
            'admin' => false
87
        ],
88
        'comment.update' => [
89
            'name' => 'Update a Comment',
90
            'description' => 'Allow the user to update a comment.',
91
            'admin' => false
92
        ],
93
        
94
        // Files
95
        'admin.file.index' => [
96
            'name' => 'View all files',
97
            'description' => 'Allow the user to view all uploaded files',
98
            'admin' => true
99
        ],
100
        'admin.file.store' => [
101
            'name' => 'Upload a new file',
102
            'description' => 'Allow the ability to upload a file on behalf of a user.',
103
            'admin' => true
104
        ],
105
        'admin.file.destroy' => [
106
            'name' => 'Delete a file',
107
            'description' => 'Allow the user to delete any uploaded file',
108
            'admin' => true
109
        ],
110
        'admin.file.update' => [
111
            'name' => 'Update a File',
112
            'description' => 'Allow the user to update any file name/description or reassign the file.',
113
            'admin' => true
114
        ],
115
        'admin.file.download' => [
116
            'name' => 'Download files',
117
            'description' => 'Allow the user to download any uploaded files',
118
            'admin' => true
119
        ],
120
        // Statuses
121
        'admin.status.create' => [
122
            'name' => 'Change document status',
123
            'description' => 'Allow the user to change the status of any file',
124
            'admin' => true
125
        ],
126
        // Comments
127
        'admin.comment.index' => [
128
            'name' => 'See comments',
129
            'description' => 'Allow the admin to see comments',
130
            'admin' => true
131
        ],
132
        'admin.comment.store' => [
133
            'name' => 'Comment',
134
            'description' => 'Allow the admin to comment in files',
135
            'admin' => true
136
        ],
137
        'admin.comment.destroy' => [
138
            'name' => 'Delete a Comment',
139
            'description' => 'Allow the admin to delete a comment.',
140
            'admin' => true
141
        ],
142
        'admin.comment.update' => [
143
            'name' => 'Update a Comment',
144
            'description' => 'Allow the admin to update a comment.',
145
            'admin' => true
146
        ],
147
    ];
148
149
    protected $events = [
150
        CommentCreated::class => [
151
            'name' => 'Comment Left',
152
            'description' => 'When a comment has been left'
153
        ],
154
        CommentDeleted::class => [
155
            'name' => 'Comment Deleted',
156
            'description' => 'When a comment has been deleted'
157
        ],
158
        CommentUpdated::class => [
159
            'name' => 'Comment Updated',
160
            'description' => 'When a comment has been updated'
161
        ],
162
        DocumentDeleted::class => [
163
            'name' => 'Document Deleted',
164
            'description' => 'When a document is deleted'
165
        ],
166
        DocumentUpdated::class => [
167
            'name' => 'Document Updated',
168
            'description' => 'When a document is updated'
169
        ],
170
        DocumentUploaded::class => [
171
            'name' => 'Document Uploaded',
172
            'description' => 'When a document is uploaded'
173
        ],
174
        StatusChanged::class => [
175
            'name' => 'Status Changed',
176
            'description' => 'When the status of a document is changed'
177
        ]
178
    ];
179
    
180
    protected $commands = [
181
        
182
    ];
183
    
184 182
    public function alias(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function alias()
Loading history...
185
    {
186 182
        return 'uploadfile';
187
    }
188
189 182
    public function namespace()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function namespace()
Loading history...
190
    {
191 182
        return '\BristolSU\Module\UploadFile\Http\Controllers';
192
    }
193
    
194 182
    public function baseDirectory()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function baseDirectory()
Loading history...
195
    {
196 182
        return __DIR__ . '/..';
197
    }
198
199 182
    public function register()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function register()
Loading history...
200
    {
201 182
        parent::register(); // TODO: Change the autogenerated stub
202 182
    }
203
204 182
    public function boot()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function boot()
Loading history...
205
    {
206 182
        parent::boot();
207
        
208 182
        $this->registerGlobalScript('modules/uploadfile/js/components.js');
209
        
210 182
        $this->app->make(CompletionConditionManager::class)->register(
211 182
            $this->alias(), 'number_of_files_submitted', NumberOfDocumentsSubmitted::class
212
        );
213 182
        $this->app->make(CompletionConditionManager::class)->register(
214 182
            $this->alias(), 'number_of_files_submitted_with_status', NumberOfDocumentsWithStatus::class
215
        );
216
        
217
        Route::bind('uploadfile_file', function($id) {
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...
218 69
            $file = File::findOrFail($id);
219 63
            if(request()->route('module_instance_slug') && (int) $file->module_instance_id === request()->route('module_instance_slug')->id()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
220 62
                return $file;
221
            }
222 1
            throw (new ModelNotFoundException)->setModel(File::class);
223 182
        });
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...
224
225
        Route::bind('uploadfile_old_file', function($id) {
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...
226 5
            $file = File::findOrFail($id);
227
            
228 4
            $currentActivityInstance = app(ActivityInstanceResolver::class)->getActivityInstance();
229 4
            $fileActivityInstance = $file->activityInstance();
230 4
            if($currentActivityInstance->resource_type === $fileActivityInstance->resource_type
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
231 4
                && (int) $currentActivityInstance->resource_id === (int) $fileActivityInstance->resource_id) {
0 ignored issues
show
Coding Style introduced by
Closing parenthesis of a multi-line IF statement must be on a new line
Loading history...
232 3
                return $file;
233
            }
234 1
            throw (new ModelNotFoundException)->setModel(File::class);
235 182
        });
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...
236
        
237
        Route::bind('uploadfile_file_status', function($id) {
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...
238
            $fileStatus = FileStatus::findOrFail($id);
239
            if(request()->route('module_instance_slug') && (int) $fileStatus->file->module_instance_id === request()->route('module_instance_slug')->id()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
240
                return $fileStatus;
241
            }
242
            throw (new ModelNotFoundException)->setModel(FileStatus::class);
243 182
        });
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...
244
        
245
        Route::bind('uploadfile_comment', function($id) {
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...
246 22
            $comment = Comment::findOrFail($id);
247 22
            if(request()->route('module_instance_slug') && (int) $comment->file->module_instance_id === request()->route('module_instance_slug')->id()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
248 22
                return $comment;
249
            }
250
            throw (new ModelNotFoundException)->setModel(Comment::class);
251 182
        });
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...
252 182
    }
253
254 182
    public function settings(): Form
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function settings()
Loading history...
255
    {
256
257 182
        return FormGenerator::make()->withGroup(
258 182
            Group::make('Page Design')->withField(
259 182
                Field::input('title')->inputType('text')->label('Module Title')->default('Page Title')
260 182
            )->withField(
261 182
                Field::textArea('description')->label('Description')->hint('This will appear at the top of the page')->rows(4)->default('Description')
262
            )
263 182
        )->withGroup(
264 182
            Group::make('New Documents')->withField(
265 182
                Field::input('document_title')->inputType('text')->label('Default document title')->hint('This will be the default title of a new file')->default('Document')
266 182
            )->withField(
267 182
                Field::switch('multiple_files')->label('Multiple Files')->hint('Should multiple files be able to be uploaded at the same time?')
268 182
                    ->textOn('Allow')->textOff('Do not allow')->default(true)
269 182
            )->withField(
270 182
                Field::checkList('allowed_extensions')->label('Allowed file types')->hint('Which file types can be uploaded?')
271 182
                    ->listBox(true)->values($this->app['config']->get($this->alias() . '.file_types'))
272 182
		                ->default(['doc', 'docx', 'odt', 'rtf', 'txt', 'csv', 'ppt', 'pptx', 'pdf', 'xls'])
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 20 spaces but found 18
Loading history...
273
            )
274 182
        )->withGroup(
275 182
            Group::make('Status Changes')->withField(
276 182
                Field::input('initial_status')->inputType('select')->label('Initial Status')->hint('What status should all new files have?')
277 182
                        ->default('Awaiting Approval')->values($this->app['config']->get($this->alias() . '.statuses'))
0 ignored issues
show
Coding Style introduced by
Object operator not indented correctly; expected 20 spaces but found 24
Loading history...
278 182
            )->withField(
279 182
                Field::checkList('statuses')->label('Available Statuses')->hint('A list of available statuses')
280 182
                    ->listBox(true)->values($this->app['config']->get($this->alias() . '.statuses'))
281
            )
282 182
        )->withGroup(
283 182
            Group::make('Tags')->withField(
284 182
                Field::make(TagList::class, 'new_tags')->label('New Tags')->hint('What tags should we assign when a new document is uploaded?')
285 182
            )->withField(
286 182
                Field::make(TagList::class, 'tags_to_merge')->label('Tags to merge')->hint('Any files with these tags will also be shown to the user')
287
            )
288 182
        )->getSchema();
289
    }
290
}