Completed
Push — b/update_guzzle ( 16f2fc...3512e8 )
by
unknown
07:47
created

ArrayUtils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 30
wmc 4
lcom 0
cbo 1
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 18 4
1
<?php
2
/**
3
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
4
 * license agreements.  See the NOTICE file distributed with this work for
5
 * additional information regarding copyright ownership.  Crate licenses
6
 * this file to you under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.  You may
8
 * obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15
 * License for the specific language governing permissions and limitations
16
 * under the License.
17
 *
18
 * However, if you have executed another commercial license agreement
19
 * with Crate these terms will supersede the license and you may use the
20
 * software solely pursuant to the terms of the relevant commercial agreement.
21
 */
22
23
namespace Crate\Stdlib;
24
25
use Traversable;
26
27
final class ArrayUtils
28
{
29
    /**
30
     * Convert a optional value that when used is expected to be an array
31
     *
32
     * @param mixed $value
33
     *
34
     * @throws Exception\InvalidArgumentException
35
     *
36
     * @return array
37
     */
38 4
    public static function toArray($value)
39
    {
40 4
        if (is_array($value)) {
41 1
            return $value;
42
        }
43
44 3
        if ($value === null) {
45 1
            return [];
46
        }
47
48 2
        if (!$value instanceof Traversable) {
49 1
            throw new Exception\InvalidArgumentException(
50
                'An invalid value was provided, should either be an null, array or Traversable'
51 1
            );
52
        }
53
54 1
        return iterator_to_array($value);
55
    }
56
}
57