Completed
Push — master ( 8507e2...2d694e )
by Lars
01:39
created

Create.php ➔ strict()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
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
                if (\count($array) === 0) {
37
                    return null;
38
                }
39
40
                return \array_keys(
41
                    \array_slice($array, -1, 1, true)
42
                )[0];
43
            }
44
        }
45
    }
46
47
}
48
49
namespace Arrayy {
50
51
    use Arrayy\Collection\Collection;
52
53
    if (!\function_exists('Arrayy\create')) {
54
        /**
55
         * Creates a Arrayy object.
56
         *
57
         * @param mixed $data
58
         *
59
         * @return Arrayy
60
         */
61
        function create($data): Arrayy
62
        {
63 1
            return new Arrayy($data);
64
        }
65
66
        /**
67
         * Creates a ArrayyStrict object.
68
         *
69
         * @param mixed $data
70
         *
71
         * @return ArrayyStrict
72
         */
73
        function strict($data): ArrayyStrict
74
        {
75 1
            return new ArrayyStrict($data);
76
        }
77
78
        /**
79
         * Creates a Collection object.
80
         *
81
         * @param string $type
82
         * @param mixed  $data
83
         *
84
         * @return Collection
85
         */
86
        function collection($type, $data = []): Collection
87
        {
88 2
            return Collection::construct($type, $data);
89
        }
90
    }
91
92
    /**
93
     * @param array $array
94
     *
95
     * @return mixed|null
96
     */
97
    function array_last(array $array)
98
    {
99 4
        $key_last = \array_key_last($array);
100 4
        if ($key_last === null) {
101 1
            return null;
102
        }
103
104 3
        return $array[$key_last];
105
    }
106
107
    /**
108
     * @param array $array
109
     *
110
     * @return mixed|null
111
     */
112
    function array_first(array $array)
113
    {
114 10
        $key_first = array_key_first($array);
115 10
        if ($key_first === null) {
116 2
            return null;
117
        }
118
119 9
        return $array[$key_first];
120
    }
121
122
}
123