Passed
Branch master (fb2e38)
by Sebastian
02:23
created

Functions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10
c 2
b 0
f 0
wmc 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ emptyMap() 0 5 1
emptyMap() 0 5 ?
A hp$0 ➔ mapOf() 0 8 1
mapOf() 0 8 ?
A hp$0 ➔ pair() 0 3 1
pair() 0 3 ?
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\Map;
13
14
use InvalidArgumentException;
15
16
final class Functions
17
{
18
    /**
19
     * @return MapInterface
20
     */
21
    public static final function emptyMap(): MapInterface
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
22
    {
23
        return new class() implements MapInterface {
24
            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...
25
            use MapTrait;
26
        };
27
    }
28
29
    /**
30
     * @param array<Pair> ...$pairs
31
     * @return MapInterface
32
     */
33 48
    public final static function mapOf(...$pairs): MapInterface
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
34
    {
35 48
        $map = emptyMap();
36 48
        $map->setArray(array_combine(
37 48
            array_map(fn (Pair $pair) => $pair->getKey(), $pairs), //keys
38 48
            array_map(fn (Pair $pair) => $pair->getValue(), $pairs) //values
39
        ));
40 48
        return $map;
41
    }
42
43
    /**
44
     * @param scalar $key
45
     * @param mixed $value
46
     * @return Pair
47
     */
48 50
    public final static function pair($key, $value): Pair
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
49
    {
50 50
        return new Pair($key, $value);
51
    }
52
}
53
54
/**
55
 * @return MapInterface
56
 */
57
function emptyMap(): MapInterface
58
{
59 53
    return Functions::emptyMap();
60
}
61
62
/**
63
 * @param array<Pair> ...$pairs
64
 * @return MapInterface
65
 */
66
function mapOf(...$pairs): MapInterface
67
{
68 48
    return Functions::mapOf(...$pairs);
69
}
70
71
/**
72
 * @param scalar $key
73
 * @param mixed $value
74
 * @return Pair
75
 */
76
function pair($key, $value): Pair
77
{
78 50
    return Functions::pair($key, $value);
79
}
80