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.

ButtonUnsubmitted::getFieldMetaData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
nc 1
nop 0
dl 0
loc 46
c 1
b 0
f 0
cc 1
rs 9.376
ccs 2
cts 2
cp 1
crap 1
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\ButtonClick;
6
use BristolSU\Module\StaticPage\Models\PageView;
7
use BristolSU\Support\Action\Contracts\TriggerableEvent;
8
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceRepository;
9
use BristolSU\Support\ModuleInstance\Contracts\ModuleInstanceRepository;
10
11
class ButtonUnsubmitted implements TriggerableEvent
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ButtonUnsubmitted
Loading history...
12
{
13
14
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
15
     * @var ButtonClick
16
     */
17
    private $buttonClick;
0 ignored issues
show
Coding Style introduced by
Private member variable "buttonClick" must be prefixed with an underscore
Loading history...
18
19 5
    public function __construct(ButtonClick $buttonClick)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
20
    {
21
22 5
        $this->buttonClick = $buttonClick;
23 5
    }
24
25
    /**
26
     * Register metadata about the fields the event supplies.
27
     *
28
     * For each field returned in getFields, pass in a label and a helptext.
29
     * e.g. [
30
     *      'user_id' => [
31
     *          'label' => 'User ID',
32
     *          'helptext' => 'The ID of the user who posted the comment.'
33
     *          ],
34
     *      ...
35
     * ]
36
     * @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...
37
     */
38 1
    public static function getFieldMetaData(): array
39
    {
40
        return [
41
          'user_id' => [
42 1
            'label' => 'User ID',
43
            'helptext' => 'The ID of the user'
44
          ],
45
          'user_email' => [
46
            'label' => 'Email Address',
47
            'helptext' => 'Email Address of the user. May be empty.'
48
          ],
49
          'user_first_name' => [
50
            'label' => 'First Name',
51
            'helptext' => 'First Name of the user. May be empty.'
52
          ],
53
          'user_last_name' => [
54
            'label' => 'Last Name',
55
            'helptext' => 'Last Name of the user. May be empty.'
56
          ],
57
          'user_preferred_name' => [
58
            'label' => 'Preferred Name',
59
            'helptext' => 'Preferred Name of the user. May be empty.'
60
          ],
61
          'module_instance_id' => [
62
            'label' => 'Module Instance ID',
63
            'helptext' => 'ID of the module instance viewed'
64
          ],
65
          'module_instance_name' => [
66
            'label' => 'Module Instance Name',
67
            'helptext' => 'Name of the module instance viewed.'
68
          ],
69
          'activity_instance_id' => [
70
            'label' => 'Activity Instance ID',
71
            'helptext' => 'The id of the activity instance viewed.'
72
          ],
73
          'activity_instance_name' => [
74
            'label' => 'Activity Instance Name',
75
            'helptext' => 'The name of the activity instance viewed.'
76
          ],
77
          'clicked_at' => [
78
            'label' => 'Button Clicked At',
79
            'helptext' => 'The date and time the button was clicked at'
80
          ],
81
          'unsubmitted_at' => [
82
            'label' => 'Button Unsubmitted At',
83
            'helptext' => 'The date and time the button was unsubmitted at'
84
          ],
85
        ];
86
    }
87
88
    /**
89
     * Get the fields that the event registers.
90
     *
91
     * If the event has parameters which should be used in the framework, return them here.
92
     *
93
     * e.g. [
94
     *      'user_id' => 1,
95
     *      'comment_id' => 4,
96
     *      'post_id' => 3
97
     * ]
98
     * @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...
99
     */
100 2
    public function getFields(): array
101
    {
102 2
        $moduleInstance = app(ModuleInstanceRepository::class)->getById($this->buttonClick->module_instance_id);
103 2
        $activityInstance = app(ActivityInstanceRepository::class)->getById($this->buttonClick->activity_instance_id);
104
        return [
105 2
          'user_id' => $this->buttonClick->user->id(),
106 2
          'user_email' => $this->buttonClick->user->data()->email(),
107 2
          'user_first_name' => $this->buttonClick->user->data()->firstName(),
108 2
          'user_last_name' => $this->buttonClick->user->data()->lastName(),
109 2
          'user_preferred_name' => $this->buttonClick->user->data()->preferredName(),
110 2
          'clicked_at' => $this->buttonClick->created_at->format('Y-m-d H:i:s'),
111 2
          'unsubmitted_at' => $this->buttonClick->deleted_at->format('Y-m-d H:i:s'),
112 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...
113 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...
114 2
          'activity_instance_id' => $activityInstance->id,
115 2
          'activity_instance_name' => $activityInstance->name,
116
        ];
117
    }
118
}
119