PostResource::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 13
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Resources;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Http\Resources\Json\Resource;
7
8
class PostResource extends Resource
9
{
10
    /**
11
     * Transform the resource into an array.
12
     *
13
     * @param  \Illuminate\Http\Request
14
     * @return array
15
     */
16
    public function toArray($request)
17
    {
18
        return [
19
            'id' => $this->id,
20
            'url' => $this->url,
21
            'url_edit' => route('backend.posts.edit', $this),
0 ignored issues
show
Documentation introduced by
$this is of type this<App\Http\Resources\PostResource>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
22
            'url_delete' => route('backend.posts.destroy', $this),
0 ignored issues
show
Documentation introduced by
$this is of type this<App\Http\Resources\PostResource>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
            'title' => Str::words($this->title, 5),
24
            'category' => $this->category->name,
25
            'tags' => $this->tags->take(3)->implode('name', ', '),
26
            'published_at' => $this->published_at->format('Y-m-d H:i'),
27
        ];
28
    }
29
}
30