EnumeratesValues::useAsCallable()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 2
nc 2
nop 1
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
}