anonymous//src/Lists/Functions.php$0
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
wmc 0
1
<?php
2
declare(strict_types=1);
3
/*
4
 * Copyright (C) 2022 Sebastian Böttger <[email protected]>
5
 * You may use, distribute and modify this code under the
6
 * terms of the MIT license.
7
 *
8
 * You should have received a copy of the MIT license with
9
 * this file. If not, please visit: https://opensource.org/licenses/mit-license.php
10
 */
11
12
namespace Seboettg\Collection\Lists;
13
14
use Seboettg\Collection\Comparable\Comparable;
15
16
final class Functions
17
{
18
    final public static function emptyList(): ListInterface
19
    {
20
        return new class() implements ListInterface {
21
            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...
22
            use ArrayListTrait;
23
        };
24
    }
25
26 62
    final public static function listOf(...$elements): ListInterface
27
    {
28 62
        return listFromArray($elements);
29
    }
30
31 64
    final public static function listFromArray($elements): ListInterface
32
    {
33 64
        $list = emptyList();
34 64
        $list->setArray(array_values($elements));
35 64
        return $list;
36
    }
37
38 2
    public static function isList($value): bool
39
    {
40 2
        return $value instanceof ListInterface;
41
    }
42
}
43
44
/**
45
 * Returns an implmentation of `ListInterface` with no entries.
46
 */
47
function emptyList(): ListInterface
48
{
49 74
    return Functions::emptyList();
50
}
51
52
/**
53
 * Returns an implementation of `ListInterface` containing passed elements
54
 */
55
function listOf(...$elements): ListInterface
56
{
57 62
    return Functions::listOf(...$elements);
58
}
59
60
/**
61
 * Returns an implementation of `ListInterface` containing all values of the passed array. The array keys are discarded.
62
 */
63
function listFromArray(array $elements): ListInterface
64
{
65 64
    return Functions::listFromArray($elements);
66
}
67
68
/**
69
 * Returns true when `$value` is an instance of `ListInterface`, otherwise false.
70
 */
71
function isList($value): bool
72
{
73 2
    return Functions::isList($value);
74
}
75