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

Find   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 54
ccs 16
cts 17
cp 0.9412
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonNotation() 0 4 1
A nativeArray() 0 4 1
A voArray() 0 11 3
A keyFromArrayValue() 0 10 3
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