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.

HasViewedPage::options()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
namespace BristolSU\Module\StaticPage\CompletionConditions;
5
6
7
use BristolSU\Module\StaticPage\Models\PageView;
8
use BristolSU\Support\ActivityInstance\ActivityInstance;
9
use BristolSU\Support\Completion\Contracts\CompletionCondition;
10
use BristolSU\Support\ModuleInstance\Contracts\ModuleInstance;
11
use FormSchema\Schema\Form;
12
13
class HasViewedPage extends CompletionCondition
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class HasViewedPage
Loading history...
14
{
15
16
    /**
17
     * Is the condition fully complete?
18
     *
19
     * @param array $settings Settings of the completion condition
0 ignored issues
show
Coding Style introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter name; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
20
     * @param ActivityInstance $activityInstance Activity instance to test
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
21
     * @param ModuleInstance $moduleInstance Module instance to test
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
22
     * @return bool If the condition is complete
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
23
     */
24 3
    public function isComplete($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): bool
25
    {
26 3
        return PageView::forResource($activityInstance->id, $moduleInstance->id)->count() >= ( $settings['number_of_views'] ?? 1);
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...
27
    }
28
29 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...
30
    {
31 5
        $count = PageView::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...
32 5
        $needed = ( $settings['number_of_views'] ?? 1);
33
        
34 5
        $percentage = (int) round(($count/$needed) * 100, 0);
35
        
36 5
        if($percentage > 100) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
37 1
            return 100;
38
        }
39 4
        return $percentage;
40
    }
41
42
    /**
43
     * Options required by the completion condition.
44
     *
45
     * Any settings requested in here will be passed into the percentage or isComplete methods.
46
     *
47
     * @return Form
48
     * @throws \Exception
49
     */
50 1
    public function options(): Form
51
    {
52 1
        return \FormSchema\Generator\Form::make()->withField(
53 1
            \FormSchema\Generator\Field::input('number_of_views')->inputType('number')->label('Number of Views')
54 1
                ->required(true)->default(1)->hint('The number of times a user needs to view the page')
55 1
                ->help('The number of times a user should view the page before the module is marked as complete. 1 will mark the module as complete on the first view, 2 on the second etc.')
56 1
        )->getSchema();
57
    }
58
59
    /**
60
     * A name for the completion condition
61
     *
62
     * @return string
63
     */
64 1
    public function name(): string
65
    {
66 1
        return 'Has viewed the page';
67
    }
68
69
    /**
70
     * A description of the completion condition
71
     *
72
     * @return string
73
     */
74 1
    public function description(): string
75
    {
76 1
        return 'Marked as complete when the user/group/role has viewed the page a number of times.';
77
    }
78
79
    /**
80
     * The alias of the completion condition
81
     *
82
     * @return string
83
     */
84 1
    public function alias(): string
85
    {
86 1
        return 'static_page_has_viewed_page';
87
    }
88
}