Value::toArrayWithPlural()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 9.4285
cc 3
eloc 8
nc 1
nop 2
crap 3
1
<?php
2
3
namespace BestServedCold\PhalueObjects\VOClosure;
4
5
use BestServedCold\PhalueObjects\VOClosure;
6
use BestServedCold\PhalueObjects\VOString\Word;
7
8
/**
9
 * Class Value
10
 *
11
 * @package BestServedCold\PhalueObjects\VOClosure
12
 */
13
class Value extends VOClosure
14
{
15
    /**
16
     * @param  bool   $pluralValue
17
     * @param  bool   $pluralKey
18
     * @return static
19
     */
20 2
    public static function toArrayWithPlural($pluralValue = false, $pluralKey = false)
21
    {
22 2
        return new static(
23 2
            function ($value) use ($pluralValue, $pluralKey) {
24 2
                return array_filter([
25 2
                    key($value),
26 2
                    reset($value),
27 2
                    $pluralKey ? Word::fromString(key($value))->getPluralised() : null,
28 2
                    $pluralValue ? Word::fromString(reset($value))->getPluralised() : null
29 2
                ]);
30
            }
31 2
        );
32
    }
33
}
34