Completed
Push — master ( 750008...8278b6 )
by Christoffer
02:27 queued 19s
created

quotedOrList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Util;
4
5
const MAX_LENGTH = 5;
6
7
/**
8
 * Given `[A, B, C]` returns `'A, B or C'`.
9
 *
10
 * @param array $items
11
 * @return string
12
 */
13
function orList(array $items): string
14
{
15
    $selected = \array_slice($items, 0, MAX_LENGTH);
16
    $allButLast = \array_slice($selected, 0, -1);
17
    return implode(', ', $allButLast) . ' or ' . $selected[\count($selected) - 1];
18
}
19
20
/**
21
 * Given `[A, B, C]` returns `'"A", "B" or "C"'`.
22
 *
23
 * @param array $items
24
 * @return string
25
 */
26
function quotedOrList(array $items): string
27
{
28
    return orList(array_map(function ($item) {
29
        return '"' . $item . '"';
30
    }, $items));
31
}
32