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.
Completed
Push — master ( 3094b9...9c33be )
by Miles
06:34
created

LoaderProvider::makeExtensions()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4286
cc 3
eloc 7
nc 4
nop 1
crap 3
1
<?php
2
3
/**
4
 * This file is part of the m1\vars library
5
 *
6
 * (c) m1 <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @package     m1/vars
12
 * @version     0.2.0
13
 * @author      Miles Croxford <[email protected]>
14
 * @copyright   Copyright (c) Miles Croxford <[email protected]>
15
 * @license     http://github.com/m1/vars/blob/master/LICENSE
16
 * @link        http://github.com/m1/vars/blob/master/README.MD Documentation
17
 */
18
19
namespace M1\Vars\Loader;
20
21
/**
22
 * This file provides the loaders and extensions supported by Vars
23
 *
24
 * @since 0.1.1
25
 */
26
class LoaderProvider
27
{
28
    /**
29
     * The available extensions
30
     *
31
     * @var array $extensions
32
     */
33
    private $extensions = array();
34
35
    /**
36
     * The available loaders
37
     *
38
     * @var array $loaders
39
     */
40
    private $loaders = array();
41
42
    /**
43
     * The constructor for LoaderProvider, makes the loaders and extensions
44
     *
45
     * @param array|null $options           The options being used for Vars
46
     * @param array      $default_loaders   The default loaders for Vars
47
     */
48 70
    public function __construct($options, $default_loaders)
49
    {
50 70
        $this->makeLoaders($options, $default_loaders);
51 68
    }
52
53
    /**
54
     * Get loaders and make extensions for the loaders
55
     *
56
     * @param array|null $options           The options being used for Vars
57
     * @param array      $default_loaders   The default loaders for Vars
58
     */
59 70
    private function makeLoaders($options, $default_loaders)
60
    {
61 70
        $parsed_loaders = array();
62
63 70
        foreach ($options['loaders'] as $loader) {
64 70
            if ($loader === 'default') {
65 2
                $parsed_loaders = array_merge($parsed_loaders, $default_loaders);
66 2
            } else {
67 69
                $parsed_loaders[] = $loader;
68
            }
69 70
        }
70
71 70
        $parsed_loaders = array_unique($parsed_loaders);
72
73 70
        $this->loaders = $this->makeNameSpaceLoaders($parsed_loaders, $default_loaders);
74 69
        $this->extensions = $this->makeExtensions($this->loaders);
75 68
    }
76
77
    /**
78
     * Makes namespace loaders from loader strings
79
     *
80
     * @param array $loaders The options being used for Vars
81
     * @param array      $default_loaders   The default loaders for Vars
82
     *
83
     * @throws \InvalidArgumentException If a loader from options isn't found
84
     * @throws \InvalidArgumentException If no loaders were loaded
85
     *
86
     * @return array The namespace loaders
87
     */
88 70
    private function makeNameSpaceLoaders($loaders, $default_loaders)
89
    {
90 70
        $parsed_loaders = array();
91
92 70
        foreach ($loaders as $loader) {
93 70
            if (in_array($loader, $default_loaders)) {
94 67
                $loader = sprintf('%s\%sLoader', __NAMESPACE__, ucfirst(strtolower($loader)));
95 67
            }
96
97 70
            if (!class_exists($loader)) {
98 1
                throw new \InvalidArgumentException(sprintf("'%s' loader class does not exist", $loader));
99
            }
100
101 69
            $parsed_loaders[] = $loader;
102 69
        }
103
104
        // @codeCoverageIgnoreStart
105
        if (empty($parsed_loaders)) {
106
            throw new \InvalidArgumentException('No loaders were loaded');
107
        }
108
        // @codeCoverageIgnoreEnd
109
110
111 69
        return $parsed_loaders;
112
    }
113
114
    /**
115
     * Get and make extensions for loaders made from makeLoaders()
116
     *
117
     * @see \M1\Vars\Vars::makeLoaders() \M1\Vars\Vars::makeLoaders()
118
     *
119
     * @param  array $loaders File loaders
120
     *
121
     * @throws \RuntimeException If no loader extensions were found
122
     *
123
     * @return array File loader supported extensions
124
     */
125 69
    private function makeExtensions(array $loaders)
126
    {
127 69
        $extensions = array();
128
129 69
        foreach ($loaders as $loader) {
130 69
            $extensions = array_merge($extensions, $loader::$supported);
131 69
        }
132
133 69
        if (empty($extensions)) {
134 1
            throw new \RuntimeException('No loader extensions were found');
135
        }
136
137 68
        return $extensions;
138
    }
139
140
    /**
141
     * Get the Vars file loaders
142
     *
143
     * @return array The Vars file loaders
144
     */
145 62
    public function getLoaders()
146
    {
147 62
        return $this->loaders;
148
    }
149
150
    /**
151
     * Get the Vars file loaders extensions
152
     *
153
     * @return array The Vars file loader extensions
154
     */
155 5
    public function getExtensions()
156
    {
157 5
        return $this->extensions;
158
    }
159
}
160