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 ( 83d765...c034ed )
by Miles
04:39
created

LoaderProvider::getLoaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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.1.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 61
    public function __construct($options, $default_loaders)
49
    {
50 61
        $this->makeLoaders($options, $default_loaders);
51 59
    }
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 61
    private function makeLoaders($options, $default_loaders)
60
    {
61 61
        $parsed_loaders = array();
62
63 61
        foreach ($options['loaders'] as $loader) {
64 61
            if ($loader === 'default') {
65 2
                $parsed_loaders = array_merge($parsed_loaders, $default_loaders);
66 2
            } else {
67 60
                $parsed_loaders[] = $loader;
68
            }
69 61
        }
70
71 61
        $parsed_loaders = array_unique($parsed_loaders);
72
73 61
        $this->loaders = $this->makeNameSpaceLoaders($parsed_loaders, $default_loaders);
74 60
        $this->extensions = $this->makeExtensions($this->loaders);
75 59
    }
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 61
    private function makeNameSpaceLoaders($loaders, $default_loaders)
89
    {
90 61
        $parsed_loaders = array();
91
92 61
        foreach ($loaders as $loader) {
93 61
            if (in_array($loader, $default_loaders)) {
94 58
                $loader = sprintf('%s\%sLoader', __NAMESPACE__, ucfirst(strtolower($loader)));
95 58
            }
96
97 61
            if (!class_exists($loader)) {
98 1
                throw new \InvalidArgumentException(sprintf("'%s' loader class does not exist", $loader));
99
            }
100
101 60
            $parsed_loaders[] = $loader;
102 60
        }
103
104 60
        if (empty($parsed_loaders)) {
105
            throw new \InvalidArgumentException('No loaders were loaded');
106
        }
107
108 60
        return $parsed_loaders;
109
    }
110
111
    /**
112
     * Get and make extensions for loaders made from makeLoaders()
113
     *
114
     * @see \M1\Vars\Vars::makeLoaders() \M1\Vars\Vars::makeLoaders()
115
     *
116
     * @param  array $loaders File loaders
117
     *
118
     * @throws \RuntimeException If no loader extensions were found
119
     *
120
     * @return array File loader supported extensions
121
     */
122 60
    private function makeExtensions(array $loaders)
123
    {
124 60
        $extensions = array();
125
126 60
        foreach ($loaders as $loader) {
127 60
            $extensions = array_merge($extensions, $loader::$supported);
128 60
        }
129
130 60
        if (empty($extensions)) {
131 1
            throw new \RuntimeException('No loader extensions were found');
132
        }
133
134 59
        return $extensions;
135
    }
136
137
    /**
138
     * Get the Vars file loaders
139
     *
140
     * @return array The Vars file loaders
141
     */
142 53
    public function getLoaders()
143
    {
144 53
        return $this->loaders;
145
    }
146
147
    /**
148
     * Get the Vars file loaders extensions
149
     *
150
     * @return array The Vars file loader extensions
151
     */
152 4
    public function getExtensions()
153
    {
154 4
        return $this->extensions;
155
    }
156
}
157