MakesAnonymousPaginationResultAwareResourceCollection   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A collection() 0 8 2
1
<?php
2
3
namespace mav3rick177\RapidPagination\Http\Resources\Json;
4
5
/**
6
 * Trait MakesAnonymousPaginationResultAwareResourceCollection
7
 *
8
 * @mixin \Illuminate\Http\Resources\Json\JsonResource
9
 */
10
trait MakesAnonymousPaginationResultAwareResourceCollection
11
{
12
    /**
13
     * Create a new anonymous resource collection.
14
     *
15
     * @param  mixed                                                       $resource
16
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
17
     */
18
    public static function collection($resource)
19
    {
20
        return tap(new AnonymousPaginationResultAwareResourceCollection($resource, static::class), function ($collection) {
21
            if (property_exists(static::class, 'preserveKeys')) {
22
                $collection->preserveKeys = (new static([]))->preserveKeys === true;
0 ignored issues
show
Bug introduced by
The property preserveKeys 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...
Unused Code introduced by
The call to MakesAnonymousPagination...llection::__construct() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
23
            }
24
        });
25
    }
26
}
27