Completed
Push — master ( e1cce4...d2c19b )
by David
09:34 queued 11s
created

UserSave::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
namespace Torralbodavid\DuckFunkCore\Exceptions\Welcome;
4
5
use Exception;
6
use Illuminate\Contracts\Validation\Validator;
7
8
class UserSave extends Exception
9
{
10
    protected $validator;
11
12
    protected $code = 422;
13
14
    public function __construct(Validator $validator)
15
    {
16
        $this->validator = $validator;
17
    }
18
19
    public function render()
20
    {
21
        dd($this->validator->errors()->first());
22
        if ($this->validator->errors()->first() == 'validation.in') {
23
            return response()->json([
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

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...
24
                'code' => 'INVALID_GENDER',
25
                'validationResult' => [
26
                    'resultType' => 'INVALID_GENDER',
27
                    'valid' => false,
28
                ],
29
            ]);
30
        }
31
32
        return response()->json([
33
            'code' => 'INVALID_NAME',
34
            'validationResult' => [
35
                'resultType' => 'VALIDATION_ERROR_UNKNOWN',
36
                'additionalInfo' => null,
37
                'valid' => false,
38
            ],
39
            'suggestions' => [],
40
        ]);
41
    }
42
}
43