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.
Passed
Push — master ( 37b02e...ebbbe1 )
by James
08:59
created

app/Api/V1/Requests/BillRequest.php (5 issues)

1
<?php
2
declare(strict_types=1);
3
/**
4
 * BillRequest.php
5
 * Copyright (c) 2018 [email protected]
6
 *
7
 * This file is part of Firefly III.
8
 *
9
 * Firefly III is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Firefly III is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
24
namespace FireflyIII\Api\V1\Requests;
25
26
use Illuminate\Validation\Validator;
27
28
/**
29
 * Class BillRequest
30
 */
31
class BillRequest extends Request
32
{
33
34
    /**
35
     * @return bool
36
     */
37
    public function authorize(): bool
38
    {
39
        // Only allow authenticated users
40
        return auth()->check();
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    public function getAll(): array
47
    {
48
        $data = [
49
            'name'        => $this->string('name'),
50
            'match'       => $this->string('match'),
51
            'amount_min'  => $this->string('amount_min'),
52
            'amount_max'  => $this->string('amount_max'),
53
            //'currency_id'   => $this->integer('currency_id'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
            //'currency_code' => $this->string('currency_code'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
            'date'        => $this->date('date'),
56
            'repeat_freq' => $this->string('repeat_freq'),
57
            'skip'        => $this->integer('skip'),
58
            'automatch'   => $this->boolean('automatch'),
59
            'active'      => $this->boolean('active'),
60
            'notes'       => $this->string('notes'),
61
        ];
62
63
        return $data;
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function rules(): array
70
    {
71
        $rules = [
72
            'name'        => 'required|between:1,255|uniqueObjectForUser:bills,name',
73
            'match'       => 'required|between:1,255|uniqueObjectForUser:bills,match',
74
            'amount_min'  => 'required|numeric|more:0',
75
            'amount_max'  => 'required|numeric|more:0',
76
            //'currency_id'   => 'numeric|exists:transaction_currencies,id|required_without:currency_code',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
            //'currency_code' => 'min:3|max:3|exists:transaction_currencies,code|required_without:currency_id',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
            'date'        => 'required|date',
79
            'repeat_freq' => 'required|in:weekly,monthly,quarterly,half-year,yearly',
80
            'skip'        => 'required|between:0,31',
81
            'automatch'   => 'required|boolean',
82
            'active'      => 'required|boolean',
83
            'notes'       => 'between:1,65536',
84
        ];
85
        switch ($this->method()) {
86
            default:
87
                break;
88
            case 'PUT':
89
            case 'PATCH':
90
                $bill           = $this->route()->parameter('bill');
91
                $rules['name']  .= ',' . $bill->id;
92
                $rules['match'] .= ',' . $bill->id;
93
                break;
94
        }
95
96
        return $rules;
97
    }
98
99
    /**
100
     * Configure the validator instance.
101
     *
102
     * @param  Validator $validator
103
     *
104
     * @return void
105
     */
106
    public function withValidator(Validator $validator): void
107
    {
108
        $validator->after(
109
            function (Validator $validator) {
110
                $data = $validator->getData();
111
                $min  = (float)($data['amount_min'] ?? 0);
112
                $max  = (float)($data['amount_max'] ?? 0);
113
                if ($min > $max) {
114
                    $validator->errors()->add('amount_min', trans('validation.amount_min_over_max'));
0 ignored issues
show
It seems like trans('validation.amount_min_over_max') can also be of type array; however, parameter $message of Illuminate\Support\MessageBag::add() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
                    $validator->errors()->add('amount_min', /** @scrutinizer ignore-type */ trans('validation.amount_min_over_max'));
Loading history...
115
                }
116
            }
117
        );
118
    }
119
}
120