Completed
Push — master ( c5400d...90bacc )
by Lars
03:23 queued 01:12
created

Create.php ➔ array_key_first()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace {
6
7
    if (\PHP_VERSION_ID < 70300) {
8
        if (!\function_exists('is_countable')) {
9
            function is_countable($var)
10
            {
11
                /** @noinspection PhpComposerExtensionStubsInspection */
12
                return \is_array($var)
13
                       ||
14
                       $var instanceof Countable
15
                       ||
16
                       $var instanceof ResourceBundle
0 ignored issues
show
Bug introduced by
The class ResourceBundle does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
17
                       ||
18
                       $var instanceof SimpleXMLElement;
19
            }
20
        }
21
22
        if (!\function_exists('array_key_first')) {
23
            function array_key_first(array $array)
24
            {
25
                foreach ($array as $key => $value) {
26
                    return $key;
27
                }
28
29
                return null;
30
            }
31
        }
32
33
        if (!\function_exists('array_key_last')) {
34
            function array_key_last(array $array)
35
            {
36
                \end($array);
37
38
                return \key($array);
39
            }
40
        }
41
    }
42
43
    if (!\function_exists('array_last')) {
44
        function array_last($array)
45
        {
46
            $key_last = \array_key_last($array);
47
48
            if ($key_last === null) {
49
                return null;
50
            }
51
52
            return $array[$key_last];
53
        }
54
    }
55
56
    if (!\function_exists('array_first')) {
57
        function array_first($array)
58
        {
59 4
            $key_first = array_key_first($array);
60 4
            if ($key_first === null) {
61 1
                return null;
62
            }
63
64 3
            return $array[$key_first];
65
        }
66
    }
67
68
}
69
70
namespace Arrayy {
71
72
    use Arrayy\Collection\Collection;
73
    use Arrayy\Collection\CollectionInterface;
74
75
    if (!\function_exists('Arrayy\create')) {
76
        /**
77
         * Creates a Arrayy object.
78
         *
79
         * @param mixed $data
80
         *
81
         * @return Arrayy
82
         */
83
        function create($data): Arrayy
84
        {
85 1
            return new Arrayy($data);
86
        }
87
88
        /**
89
         * Creates a Collection object.
90
         *
91
         * @param string $type
92
         * @param mixed  $data
93
         *
94
         * @return CollectionInterface
95
         */
96
        function collection($type, $data = []): CollectionInterface
97
        {
98 2
            return new Collection($type, $data);
99
        }
100
    }
101
102
}
103