GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Factory::create()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 9
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Novactive Collection.
4
 *
5
 * @author    Luke Visinoni <[email protected], [email protected]>
6
 * @author    Sébastien Morel <[email protected], [email protected]>
7
 * @copyright 2017 Novactive
8
 * @license   MIT
9
 */
10
11
namespace Novactive\Collection;
12
13
use Traversable;
14
15
/**
16
 * Class Factory.
17
 */
18
class Factory
19
{
20
    /**
21
     * @param Traversable|array $items
22
     * @param string            $className
23
     *
24
     * @return Collection
25
     */
26 148
    public static function create($items = [], $className = 'Novactive\Collection\Collection')
27
    {
28 148
        $options = null;
29 148
        if (getenv('DEBUG_COLLECTION_CLASS') && getenv('DEBUG_COLLECTION_CLASS') != '') {
30
            $className = getenv('DEBUG_COLLECTION_CLASS');
31
        }
32
33 148
        return new $className(static::getArrayForItems($items), $options);
34
    }
35
36
    /**
37
     * @param $items
38
     *
39
     * @return array
40
     */
41 148
    public static function getArrayForItems($items)
42
    {
43 148
        if ($items instanceof Collection) {
44 8
            return $items->toArray();
45 146
        } elseif (is_array($items)) {
46 144
            return $items;
47 5
        } elseif ($items instanceof Traversable) {
48 1
            return iterator_to_array($items);
49 4
        } elseif (is_string($items)) {
50 4
            $json = json_decode($items, true);
51 4
            if (is_array($json) && json_last_error() == JSON_ERROR_NONE) {
52 4
                return $json;
53
            }
54
        }
55
56
        return (array)$items;
57
    }
58
}
59