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.

NumberOfDocumentsSubmitted::alias()   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 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 0
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\CompletionConditions;
4
5
use BristolSU\Module\UploadFile\Models\File;
6
use BristolSU\Support\ActivityInstance\ActivityInstance;
7
use BristolSU\Support\Completion\Contracts\CompletionCondition;
8
use BristolSU\Support\ModuleInstance\Contracts\ModuleInstance;
9
use FormSchema\Schema\Form;
10
11
class NumberOfDocumentsSubmitted extends CompletionCondition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class NumberOfDocumentsSubmitted
Loading history...
12
{
13
    
14 3
    public function isComplete($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isComplete()
Loading history...
15
    {
16 3
        return File::forResource($activityInstance->id, $moduleInstance->id())->count() >= $settings['number_of_files'];
17
    }
18
19 5
    public function percentage($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): int
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function percentage()
Loading history...
20
    {
21 5
        $count = File::forResource($activityInstance->id, $moduleInstance->id)->count();
0 ignored issues
show
Bug introduced by
Accessing id on the interface BristolSU\Support\Module...ontracts\ModuleInstance suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
22 5
        $needed = ( $settings['number_of_files'] ?? 1);
23
24 5
        $percentage = (int) round(($count/$needed) * 100, 0);
25
26 5
        if($percentage > 100) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
27 1
            return 100;
28
        }
29 4
        return $percentage;
30
    }
31
32
33 1
    public function options(): Form
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function options()
Loading history...
34
    {
35 1
        return \FormSchema\Generator\Form::make()->withField(
36 1
            \FormSchema\Generator\Field::input('number_of_files')->inputType('number')->label('Number of Files')
37 1
                ->required(true)->default(1)->hint('The number of files that must be submitted')
38 1
                ->help('The number of documents that need to be submitted for the module to be marked as complete.')
39 1
        )->getSchema();
40
    }
41
42 1
    public function name(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function name()
Loading history...
43
    {
44 1
        return 'A number of documents have been submitted';
45
    }
46
47 1
    public function description(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function description()
Loading history...
48
    {
49 1
        return 'Complete when a given number of documents have been submitted';
50
    }
51
52 1
    public function alias(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function alias()
Loading history...
53
    {
54 1
        return 'number_of_files_submitted';
55
    }
56
}