Completed
Pull Request — master (#156)
by Lucas
03:54 queued 01:43
created

ToPairs   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPairs() 0 8 1
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Support\Collection;
6
7
class ToPairs
8
{
9
    /**
10
     * Transform a collection into an an array with pairs.
11
     *
12
     * @return \Illuminate\Support\Collection
13
     */
14
    public function toPairs()
15
    {
16
        return function (): Collection {
17
            return $this->keys()->map(function ($key) {
0 ignored issues
show
Bug introduced by
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...
18
                return [$key, $this->items[$key]];
0 ignored issues
show
Bug introduced by
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...
19
            });
20
        };
21
    }
22
}
23