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 ( a07f0a...79e180 )
by Miles
05:56
created

DirectoryLoader::load()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4286
cc 3
eloc 7
nc 3
nop 0
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.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 dir loading support for Vars
23
 *
24
 * @since 0.1.1
25
 */
26
class DirectoryLoader extends AbstractLoader
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31 4
    public function load()
32
    {
33 4
        $paths = array();
34
35 4
        foreach ($this->getSupportedFiles() as $path => $file) {
36 2
            if ($file->isFile()) {
37 2
                $paths[] = $path;
38 2
            }
39 4
        }
40 4
        $this->content = $this->makeResources($paths);
41
42 4
        return $this;
43
    }
44
45
    /**
46
     * Returns the supported files in the directory
47
     *
48
     * @return array The supported files in the directory
49
     */
50 4
    private function getSupportedFiles()
51
    {
52 4
        $dir_it = new \RecursiveDirectoryIterator($this->entity, \RecursiveDirectoryIterator::SKIP_DOTS);
53
54 4
        $dir_files = new \RecursiveIteratorIterator(
55 4
            $dir_it,
56 4
            \RecursiveIteratorIterator::LEAVES_ONLY,
57
            \RecursiveIteratorIterator::CATCH_GET_CHILD
58 4
        );
59
60 4
        $supported_files = new \RegexIterator(
61 4
            $dir_files,
62 4
            '/^.*\.(' . implode('|', static::$supported) . ')$/i'
63 4
        );
64
65 4
        return $supported_files;
66
    }
67
68
    /**
69
     * Makes usable resource paths from path strings
70
     *
71
     * @param array $paths The path strings
72
     *
73
     * @return array|bool  The usable resources if any, else false
74
     */
75 4
    private function makeResources($paths)
76
    {
77 4
        if ($paths && !empty($paths)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $paths of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
78 2
            $resources = array();
79
80 2
            foreach ($paths as $path) {
81 2
                $resources[] = $path;
82 2
            }
83
84 2
            return $resources;
85
        }
86
87 2
        return false;
88
    }
89
}
90