Passed
Push — master ( 51edae...d29a9b )
by Curtis
11:52 queued 05:54
created

Files::toResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 9.9
1
<?php
2
3
namespace App\Http\Response\enso\files;
4
5
use Illuminate\Contracts\Support\Responsable;
6
use LaravelEnso\Files\Http\Resources\Collection;
7
use App\Http\Resources\enso\files\File as Resource;
8
use App\Models\enso\files\File;
9
10
class Files implements Responsable
11
{
12
    public function toResponse($request)
13
    {
14
        return new Collection(
0 ignored issues
show
Bug Best Practice introduced by
The expression return new LaravelEnso\F...es.paginate'))->get())) returns the type LaravelEnso\Files\Http\Resources\Collection which is incompatible with the return type mandated by Illuminate\Contracts\Sup...sponsable::toResponse() of Symfony\Component\HttpFoundation\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
15
            Resource::collection(
16
                File::visible()
17
                    ->with(['createdBy.avatar', 'attachable'])
18
                    ->forUser($request->user())
19
                    ->between(json_decode($request->get('interval')))
20
                    ->filter($request->get('query'))
21
                    ->ordered()
22
                    ->skip($request->get('offset'))
23
                    ->take(config('enso.files.paginate'))
24
                    ->get()
25
            )
26
        );
27
    }
28
}
29