Passed
Branch version-4 (8b03a3)
by Sebastian
02:18
created

Functions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 31
ccs 13
cts 13
cp 1
rs 10
wmc 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ listOf() 0 5 1
listOf() 0 5 ?
A strval() 0 13 5
A hp$0 ➔ emptyList() 0 5 1
emptyList() 0 5 ?
1
<?php
2
3
namespace Seboettg\Collection\Lists;
4
5
final class Functions
6
{
7
8 3
    public static final function strval($value): string
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
9
    {
10 3
        if (is_double($value)) {
11 2
            $str = \strval($value);
12 2
            if (strlen($str) == 1) {
13 1
                return sprintf("%1\$.1f",$value);
14
            }
15 2
            return \strval($value);
16
        }
17 2
        if (is_bool($value)) {
18 1
            return $value ? "true" : "false";
19
        }
20 2
        return "$value";
21
    }
22
23
    public static final function emptyList(): ListInterface
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
24
    {
25
        return new class() implements ListInterface {
26
            private $array = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "array" must contain a leading underscore
Loading history...
introduced by
The private property $array is not used, and could be removed.
Loading history...
27
            use ArrayListTrait;
28
        };
29
    }
30
31 16
    public static final function listOf(...$elements): ListInterface
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
32
    {
33 16
        $list = emptyList();
34 16
        $list->setArray(array_values($elements));
35 16
        return $list;
36
    }
37
}
38
39
function strval($value): string
40
{
41 3
    return Functions::strval($value);
42
}
43
44
function emptyList(): ListInterface
45
{
46 21
    return Functions::emptyList();
47
}
48
49
function listOf(...$elements): ListInterface
50
{
51 16
    return Functions::listOf(...$elements);
52
}
53
54
function tuple($first, $second): Tuple
55
{
56
    return new Tuple($first, $second);
57
}
58