EnumeratesValues   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 6
c 1
b 0
f 1
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A valueRetriever() 0 8 2
A useAsCallable() 0 3 2
1
<?php
2
3
namespace Nip\Collections\Traits;
4
5
trait EnumeratesValues
6
{
7
    /**
8
     * Get a value retrieving callback.
9
     *
10
     * @param  callable|string|null  $value
11
     * @return callable
12
     */
13
    protected function valueRetriever($value)
14
    {
15
        if ($this->useAsCallable($value)) {
16
            return $value;
17
        }
18
19
        return function ($item) use ($value) {
20
            return data_get($item, $value);
21
        };
22
    }
23
24
    /**
25
     * Determine if the given value is callable, but not a string.
26
     *
27
     * @param  mixed  $value
28
     * @return bool
29
     */
30
    protected function useAsCallable($value)
31
    {
32
        return ! is_string($value) && is_callable($value);
33
    }
34
}