ToPairs   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 11
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 1
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Support\Collection;
6
7
/**
8
 * Transform a collection into an an array with pairs.
9
 *
10
 * @mixin \Illuminate\Support\Collection
11
 *
12
 * @return \Illuminate\Support\Collection
13
 */
14
class ToPairs
15
{
16
    public function __invoke()
17
    {
18
        return function (): Collection {
19
            return $this->keys()->map(function ($key) {
0 ignored issues
show
Bug introduced by Lucas Michot
The method keys() does not seem to exist on object<Spatie\CollectionMacros\Macros\ToPairs>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
20
                return [$key, $this->items[$key]];
0 ignored issues
show
Bug introduced by Lucas Michot
The property items 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...
21
            });
22
        };
23
    }
24
}
25