Completed
Push — master ( a4e176...8c9478 )
by Adam
02:50
created

Find::voArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
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
trait Find
14
{
15
    /**
16
     * @param  Notation $notation
17
     * @return bool
18
     */
19 2
    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 2
        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 3
    public function voArray(VOArray $arrayValueObject)
41
    {
42 3
        if ($key = VOArray::fromArray($this->getValue())->getKey($arrayValueObject->current())) {
0 ignored issues
show
Bug introduced by
It seems like getValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
43 3
            return $arrayValueObject->isLast() ? $key
44 3
                : VOArray::fromArray($key)
45 3
                    ->voArray($arrayValueObject->dropFirst());
46
        }
47
48 2
        return false;
49
    }
50
}
51