Find::keyFromArrayValue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
crap 3.0416
1
<?php
2
3
namespace BestServedCold\PhalueObjects\VOArray;
4
5
use BestServedCold\PhalueObjects\Format\Json\Notation;
6
use BestServedCold\PhalueObjects\VOArray;
7
8
/**
9
 * Class Find
10
 *
11
 * @package BestServedCold\PhalueObjects\VOArray
12
 */
13
class Find extends VOArray
14
{
15
    /**
16
     * @param  Notation $notation
17
     * @return bool
18
     */
19 1
    public function jsonNotation(Notation $notation)
0 ignored issues
show
Coding Style introduced by
function jsonNotation() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
20
    {
21 1
        return $this->voArray($notation->toVOArray());
22
    }
23
24
    /**
25
     * @param  array $array
26
     * @return bool|mixed
27
     */
28 1
    public function nativeArray(array $array)
29
    {
30 1
        return $this->voArray(VOArray::fromArray($array));
31
    }
32
33
    /**
34
     * Iterates through an array of values and finds a key.  If it makes it to the final value,
35
     * it returns what ever value matches that key.
36
     *
37
     * @param  VOArray    $arrayValueObject
38
     * @return bool|mixed
39
     */
40 2
    public function voArray(VOArray $arrayValueObject)
41
    {
42 2
        if ($key = VOArray::fromArray($this->getValue())->getKey($arrayValueObject->current())) {
43 2
            return $arrayValueObject->isLast() ? $key
44 2
                : static::fromArray($key)
45 2
                    ->voArray($arrayValueObject->dropFirst());
46
        }
47
48 2
        return false;
49
    }
50
51
    /**
52
     * @param  $arrayValue
53
     * @return int|string
54
     */
55 2
    public function keyFromArrayValue($arrayValue)
56
    {
57 2
        foreach ($this->getValue() as $key => $value) {
58 2
            if (in_array(strtolower($arrayValue), array_map('strtolower', $value))) {
59 2
                return $key;
60
            }
61 2
        }
62
    }
63
}
64