Passed
Push — version-4 ( db79e6...123e06 )
by Sebastian
02:21
created

array_unique()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Seboettg\Collection\Lists;
4
5
use Seboettg\Collection\Comparable\Comparable;
6
use Stringable;
7
8
final class Functions
9
{
10
11 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...
12
    {
13 3
        if (is_double($value)) {
14 2
            $str = \strval($value);
15 2
            if (strlen($str) == 1) {
16 1
                return sprintf("%1\$.1f",$value);
17
            }
18 2
            return \strval($value);
19
        }
20 2
        if (is_bool($value)) {
21 1
            return $value ? "true" : "false";
22
        }
23 2
        return "$value";
24
    }
25
26
    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...
27
    {
28
        return new class() implements ListInterface {
29
            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...
30
            use ArrayListTrait;
31
        };
32
    }
33
34 36
    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...
35
    {
36 36
        return listFromArray($elements);
37
    }
38
39 36
    public static final function listFromArray($elements): ListInterface
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
40
    {
41 36
        $list = emptyList();
42 36
        $list->setArray(array_values($elements));
43 36
        return $list;
44
    }
45
46 5
    public static function isScalarOrStringable($object)
47
    {
48 5
        return is_scalar($object)
49 5
            || method_exists($object, "__toString");
50
    }
51
52 2
    public static function isComparable($object): bool
53
    {
54 2
        return $object instanceof Comparable;
55
    }
56
}
57
58
function strval($value): string
59
{
60 3
    return Functions::strval($value);
61
}
62
63
function array_unique(array $array): array
64
{
65
    return Functions::array_unique($array);
0 ignored issues
show
Bug introduced by
The method array_unique() does not exist on Seboettg\Collection\Lists\Functions. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
    return Functions::/** @scrutinizer ignore-call */ array_unique($array);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
}
67
68
function emptyList(): ListInterface
69
{
70 42
    return Functions::emptyList();
71
}
72
73
function listOf(...$elements): ListInterface
74
{
75 36
    return Functions::listOf(...$elements);
76
}
77
78
function listFromArray(array $elements): ListInterface
79
{
80 36
    return Functions::listFromArray($elements);
81
}
82
83
function isScalarOrStringable($object): bool
84
{
85 5
    return Functions::isScalarOrStringable($object);
86
}
87
88
function isComparable($object): bool
89
{
90
    return Functions::isComparable($object);
91
}