ArticleSerializer::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 1
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace App\GraphQL\Serializers;
12
13
use App\Models\Article;
14
use Illuminate\Database\Eloquent\Model;
15
16
/**
17
 * Class ArticleSerializer.
18
 */
19
class ArticleSerializer extends AbstractSerializer
20
{
21
    /**
22
     * @param  Article|Model $article
23
     * @return array
24
     */
25
    public function toArray($article): array
26
    {
27
        return [
28
            'id'             => $article->id,
29
            'title'          => $article->capitalize_title,
30
            'slug'           => $article->slug,
31
            'url'            => route('articles.show', ['slug' => $article->slug]),
32
            'image'          => $article->image_url,
33
            'content'        => $article->content_rendered,
34
            'content_source' => $article->content_source,
35
            'preview'        => $article->preview_rendered,
36
            'preview_source' => $article->preview_source,
37
            'status'         => $article->status,
38
            'published_at'   => $this->formatDateTime($article->published_at),
39
            'user'           => UserSerializer::serialize($article->user),
40
            'tags'           => TagSerializer::collection($article->tags),
41
        ];
42
    }
43
}
44