Completed
Push — 2.0 ( 3d053b...00ad30 )
by Kirill
03:09
created

AuthUserSerializer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace App\GraphQL\Serializers;
11
12
use App\Models\User;
13
use App\Services\TokenAuth;
14
use Illuminate\Database\Eloquent\Model;
15
16
/**
17
 * Class AuthUserSerializer.
18
 */
19
class AuthUserSerializer extends UserSerializer
20
{
21
    /**
22
     * @var TokenAuth
23
     */
24
    private $tokenAuth;
25
26
    /**
27
     * AuthUserSerializer constructor.
28
     * @param TokenAuth $tokenAuth
29
     */
30
    public function __construct(TokenAuth $tokenAuth)
31
    {
32
        $this->tokenAuth = $tokenAuth;
33
    }
34
35
    /**
36
     * @param  User|Model $user
37
     * @return array
38
     */
39
    public function toArray($user): array
40
    {
41
        return array_merge(parent::toArray($user), [
42
            'token' => $this->tokenAuth->fromUser($user),
0 ignored issues
show
Bug introduced by
It seems like $user defined by parameter $user on line 39 can also be of type object<Illuminate\Database\Eloquent\Model>; however, App\Services\TokenAuth::fromUser() does only seem to accept object<Illuminate\Contracts\Auth\Authenticatable>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
43
        ]);
44
    }
45
}
46