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.
Passed
Push — develop ( a1ecb7...a37349 )
by Sébastien
02:34
created

Factory   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 78.95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 41
ccs 15
cts 19
cp 0.7895
rs 10
c 1
b 0
f 0
wmc 10
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 3
B getArrayForItems() 0 17 7
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 123
    public static function create($items = [], $className = 'Novactive\Collection\Collection')
27
    {
28 123
        $options = null;
29 123
        if (getenv('DEBUG_COLLECTION_CLASS') && getenv('DEBUG_COLLECTION_CLASS') != '') {
30
            $className = getenv('DEBUG_COLLECTION_CLASS');
31
        }
32
33 123
        return new $className(static::getArrayForItems($items), $options);
34
    }
35
36
    /**
37
     * @param $items
38
     *
39
     * @return array
40
     */
41 123
    public static function getArrayForItems($items)
42
    {
43 123
        if ($items instanceof Collection) {
44 8
            return $items->toArray();
45 121
        } elseif (is_array($items)) {
46 119
            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