RespondsWithPaginationResult   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A toResponse() 0 11 3
1
<?php
2
3
namespace mav3rick177\RapidPagination\Http\Resources\Json;
4
5
use Illuminate\Http\Resources\Json\PaginatedResourceResponse;
6
use Illuminate\Pagination\AbstractPaginator;
7
use mav3rick177\RapidPagination\PaginationResult;
8
9
/**
10
 * Trait RespondsWithPaginationResult
11
 *
12
 * @mixin \Illuminate\Http\Resources\Json\ResourceCollection
13
 */
14
trait RespondsWithPaginationResult
15
{
16
    /**
17
     * Create an HTTP response that represents the object.
18
     *
19
     * @param  \Illuminate\Http\Request      $request
20
     * @return \Illuminate\Http\JsonResponse
21
     */
22
    public function toResponse($request)
23
    {
24
        if ($this->resource instanceof AbstractPaginator) {
0 ignored issues
show
Bug introduced by
The property resource does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
            return (new PaginatedResourceResponse($this))->toResponse($request);
26
        }
27
        if ($this->resource instanceof PaginationResult) {
28
            return (new PaginationResultResourceResponse($this))->toResponse($request);
29
        }
30
31
        return parent::toResponse($request);
32
    }
33
}
34