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.

PageViewed::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
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\StaticPage\Events;
4
5
use BristolSU\Module\StaticPage\Models\PageView;
6
use BristolSU\Support\Action\Contracts\TriggerableEvent;
7
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceRepository;
8
use BristolSU\Support\ModuleInstance\Contracts\ModuleInstanceRepository;
9
10
class PageViewed implements TriggerableEvent
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class PageViewed
Loading history...
11
{
12
13
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
14
     * @var PageView
15
     */
16
    private $pageView;
0 ignored issues
show
Coding Style introduced by
Private member variable "pageView" must be prefixed with an underscore
Loading history...
17
18 5
    public function __construct(PageView $pageView)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
19
    {
20
21 5
        $this->pageView = $pageView;
22 5
    }
23
24
    /**
25
     * Register metadata about the fields the event supplies.
26
     *
27
     * For each field returned in getFields, pass in a label and a helptext.
28
     * e.g. [
29
     *      'user_id' => [
30
     *          'label' => 'User ID',
31
     *          'helptext' => 'The ID of the user who posted the comment.'
32
     *          ],
33
     *      ...
34
     * ]
35
     * @return array
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
36
     */
37 1
    public static function getFieldMetaData(): array
38
    {
39
        return [
40
            'user_id' => [
41 1
                'label' => 'User ID',
42
                'helptext' => 'The ID of the user'
43
            ],
44
            'user_email' => [
45
                'label' => 'Email Address',
46
                'helptext' => 'Email Address of the user. May be empty.'
47
            ],
48
            'user_first_name' => [
49
                'label' => 'First Name',
50
                'helptext' => 'First Name of the user. May be empty.'
51
            ],
52
            'user_last_name' => [
53
                'label' => 'Last Name',
54
                'helptext' => 'Last Name of the user. May be empty.'
55
            ],
56
            'user_preferred_name' => [
57
                'label' => 'Preferred Name',
58
                'helptext' => 'Preferred Name of the user. May be empty.'
59
            ],
60
            'module_instance_id' => [
61
                'label' => 'Module Instance ID',
62
                'helptext' => 'ID of the module instance viewed'
63
            ],
64
            'module_instance_name' => [
65
                'label' => 'Module Instance Name',
66
                'helptext' => 'Name of the module instance viewed.'
67
            ],
68
            'activity_instance_id' => [
69
                'label' => 'Activity Instance ID',
70
                'helptext' => 'The id of the activity instance viewed.'
71
            ],
72
            'activity_instance_name' => [
73
                'label' => 'Activity Instance Name',
74
                'helptext' => 'The name of the activity instance viewed.'
75
            ],
76
        ];
77
    }
78
79
    /**
80
     * Get the fields that the event registers.
81
     *
82
     * If the event has parameters which should be used in the framework, return them here.
83
     *
84
     * e.g. [
85
     *      'user_id' => 1,
86
     *      'comment_id' => 4,
87
     *      'post_id' => 3
88
     * ]
89
     * @return array
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
90
     */
91 2
    public function getFields(): array
92
    {
93 2
        $moduleInstance = app(ModuleInstanceRepository::class)->getById($this->pageView->module_instance_id);
94 2
        $activityInstance = app(ActivityInstanceRepository::class)->getById($this->pageView->activity_instance_id);
95
        return [
96 2
            'user_id' => $this->pageView->user->id(),
97 2
            'user_email' => $this->pageView->user->data()->email(),
98 2
            'user_first_name' => $this->pageView->user->data()->firstName(),
99 2
            'user_last_name' => $this->pageView->user->data()->lastName(),
100 2
            'user_preferred_name' => $this->pageView->user->data()->preferredName(),
101 2
            'module_instance_id' => $moduleInstance->id,
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...
102 2
            'module_instance_name' => $moduleInstance->name,
0 ignored issues
show
Bug introduced by
Accessing name on the interface BristolSU\Support\Module...ontracts\ModuleInstance suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
103 2
            'activity_instance_id' => $activityInstance->id,
104 2
            'activity_instance_name' => $activityInstance->name,
105
        ];
106
    }
107
}