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.

Code Duplication    Length = 43-46 lines in 2 locations

app/Repositories/VariableRepository.php 2 locations

@@ 46-88 (lines=43) @@
43
     * @throws \Pterodactyl\Exceptions\DisplayException
44
     * @throws \Pterodactyl\Exceptions\DisplayValidationException
45
     */
46
    public function create($option, array $data)
47
    {
48
        $option = ServiceOption::select('id')->findOrFail($option);
49
50
        $validator = Validator::make($data, [
51
            'name' => 'required|string|min:1|max:255',
52
            'description' => 'sometimes|nullable|string',
53
            'env_variable' => 'required|regex:/^[\w]{1,255}$/',
54
            'default_value' => 'string',
55
            'options' => 'sometimes|required|array',
56
            'rules' => 'bail|required|string|min:1',
57
        ]);
58
59
        // Ensure the default value is allowed by the rules provided.
60
        $rules = (isset($data['rules'])) ? $data['rules'] : $variable->rules;
61
        $validator->sometimes('default_value', $rules, function ($input) {
62
            return $input->default_value;
63
        });
64
65
        if ($validator->fails()) {
66
            throw new DisplayValidationException($validator->errors());
67
        }
68
69
        if (isset($data['env_variable'])) {
70
            $search = ServiceVariable::where('env_variable', $data['env_variable'])->where('option_id', $option->id);
71
            if ($search->first()) {
72
                throw new DisplayException('The envionment variable name assigned to this variable must be unique for this service option.');
73
            }
74
        }
75
76
        if (! isset($data['options']) || ! is_array($data['options'])) {
77
            $data['options'] = [];
78
        }
79
80
        $data['option_id'] = $option->id;
81
        $data['user_viewable'] = (in_array('user_viewable', $data['options']));
82
        $data['user_editable'] = (in_array('user_editable', $data['options']));
83
84
        // Remove field that isn't used.
85
        unset($data['options']);
86
87
        return ServiceVariable::create($data);
88
    }
89
90
    /**
91
     * Deletes a specified option variable as well as all server
@@ 120-165 (lines=46) @@
117
     * @throws \Pterodactyl\Exceptions\DisplayException
118
     * @throws \Pterodactyl\Exceptions\DisplayValidationException
119
     */
120
    public function update($id, array $data)
121
    {
122
        $variable = ServiceVariable::findOrFail($id);
123
124
        $validator = Validator::make($data, [
125
            'name' => 'sometimes|required|string|min:1|max:255',
126
            'description' => 'sometimes|nullable|string',
127
            'env_variable' => 'sometimes|required|regex:/^[\w]{1,255}$/',
128
            'default_value' => 'string',
129
            'options' => 'sometimes|required|array',
130
            'rules' => 'bail|sometimes|required|string|min:1',
131
        ]);
132
133
        // Ensure the default value is allowed by the rules provided.
134
        $rules = (isset($data['rules'])) ? $data['rules'] : $variable->rules;
135
        $validator->sometimes('default_value', $rules, function ($input) {
136
            return $input->default_value;
137
        });
138
139
        if ($validator->fails()) {
140
            throw new DisplayValidationException($validator->errors());
141
        }
142
143
        if (isset($data['env_variable'])) {
144
            $search = ServiceVariable::where('env_variable', $data['env_variable'])
145
                ->where('option_id', $variable->option_id)
146
                ->where('id', '!=', $variable->id);
147
            if ($search->first()) {
148
                throw new DisplayException('The envionment variable name assigned to this variable must be unique for this service option.');
149
            }
150
        }
151
152
        if (! isset($data['options']) || ! is_array($data['options'])) {
153
            $data['options'] = [];
154
        }
155
156
        $data['user_viewable'] = (in_array('user_viewable', $data['options']));
157
        $data['user_editable'] = (in_array('user_editable', $data['options']));
158
159
        // Remove field that isn't used.
160
        unset($data['options']);
161
162
        $variable->fill($data)->save();
163
164
        return $variable;
165
    }
166
}
167