AuthUserSerializer::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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),
43
        ]);
44
    }
45
}
46