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.

TransactionRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 60
rs 10
c 2
b 0
f 0
wmc 3
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
A messages() 0 10 1
B rules() 0 26 1
1
<?php
2
3
namespace App\Http\Requests\Api;
4
5
use Carbon\Carbon;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Illuminate\Validation\Rule;
8
9
class TransactionRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize()
17
    {
18
        return true;
19
    }
20
21
    /**
22
     * Get custom messages for validator errors.
23
     *
24
     * @return array
25
     */
26
    public function messages()
27
    {
28
        return [
29
            'account.exists'            => 'no entry found for account',
30
            'transaction_status.exists' => 'no entry found for transaction_status',
31
            'transaction_type.exists'   => 'no entry found for transaction_type',
32
            'category.exists'           => 'no entry found for category',
33
            'subcategory.exists'        => 'no entry found for subcategory',
34
        ];
35
    }
36
37
    /**
38
     * Get the validation rules that apply to the request.
39
     *
40
     * @return array
41
     */
42
    public function rules()
43
    {
44
        return [
45
            'transaction_date'   => 'nullable|date|date_format:'.Carbon::ATOM,
46
            'transaction_status' => 'string|exists:transaction_status,name',
47
            'transaction_type'   => 'required|string|exists:transaction_types,name',
48
            'account'            => [
49
                'required',
50
                'string',
51
                Rule::exists('accounts', 'name')->where('user_id', auth()->user()->id),
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
52
            ],
53
            'to_account'         => 'sometimes|required|string',
54
            'payee'              => 'sometimes|required|string',
55
            'category'           => [
56
                'required',
57
                'string',
58
                Rule::exists('categories', 'name')->where('user_id', auth()->user()->id)->whereNull('parent_id'),
59
            ],
60
            'subcategory'        => [
61
                'string',
62
                Rule::exists('categories', 'name')->where('user_id', auth()->user()->id)->whereNotNull('parent_id'),
63
            ],
64
            'amount'             => 'required|numeric|min:0|max:999999',
65
            'notes'              => 'string|nullable',
66
        ];
67
    }
68
}
69