Completed
Pull Request — master (#24)
by Adam
02:31
created

Find::jsonNotation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects\VOArray;
4
5
use BestServedCold\PhalueObjects\Format\String\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
        $key = VOArray::fromArray($this->getValue())->getKey($arrayValueObject->current());
43 2
        if ($key) {
44 2
            return $arrayValueObject->isLast() ? $key
45 2
                : static::fromArray($key)
46 2
                    ->voArray($arrayValueObject->dropFirst());
47
        }
48
49 2
        return false;
50
    }
51
52
    /**
53
     * @param  $arrayValue
54
     * @return int|string
55
     */
56 2
    public function keyFromArrayValue($arrayValue)
57
    {
58 2
        foreach ($this->getValue() as $key => $value) {
59 2
            if (in_array(strtolower($arrayValue), array_map('strtolower', $value))) {
60 2
                return $key;
61
            }
62 2
        }
63
64
        return false;
65
    }
66
}
67