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.

DirectoryLoader::getSupportedFilesRecursively()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
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     1.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
     * Construct the loader with the passed entity
30
     *
31
     * @param string $entity    The passed entity
32
     * @param bool   $recursive Search the directories   recursively
33
     */
34 7
    public function __construct($entity, $recursive)
35
    {
36 7
        parent::__construct($entity);
37 7
        $this->recursive = $recursive;
0 ignored issues
show
Bug introduced by
The property recursive does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38 7
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 7
    public function load()
44
    {
45 7
        $paths = array();
46 7
        $files = ($this->recursive) ? $this->getSupportedFilesRecursively() : $this->getSupportedFiles();
47
48 7
        foreach ($files as $path => $file) {
49 5
            if ($file->isFile()) {
50 5
                $paths[] = $path;
51
            }
52
        }
53 7
        $this->content = $this->makeResources($paths);
54
55 7
        return $this;
56
    }
57
58
    /**
59
     * Returns the supported files in the directory recursively
60
     *
61
     * @return \RegexIterator The supported files in the directories
62
     */
63 2
    private function getSupportedFilesRecursively()
64
    {
65 2
        $dir_it = new \RecursiveDirectoryIterator($this->entity, \RecursiveDirectoryIterator::SKIP_DOTS);
66
67 2
        $files = new \RecursiveIteratorIterator(
68 2
            $dir_it,
69 2
            \RecursiveIteratorIterator::LEAVES_ONLY,
70 2
            \RecursiveIteratorIterator::CATCH_GET_CHILD
71
        );
72
73 2
        return $this->createRegexIterator($files);
74
    }
75
76
    /**
77
     * Returns the supported files in the directory
78
     *
79
     * @return \RegexIterator The supported files in the directory
80
     */
81 5
    private function getSupportedFiles()
82
    {
83 5
        $files = new \FilesystemIterator($this->entity);
84
85 5
        return $this->createRegexIterator($files);
86
    }
87
88
    /**
89
     * Returns the supported files in the directory
90
     *
91
     * @param \FilesystemIterator|\RecursiveIteratorIterator $files The found files in the directory/ies
92
     *
93
     * @return \RegexIterator The supported files in the directory using the regexiterator
94
     */
95 7
    private function createRegexIterator($files)
96
    {
97 7
        return new \RegexIterator(
98 7
            $files,
99 7
            '/^.*\.(' . implode('|', static::$supported) . ')$/i'
100
        );
101
    }
102
103
    /**
104
     * Makes usable resource paths from path strings
105
     *
106
     * @param array $paths The path strings
107
     *
108
     * @return array|bool  The usable resources if any, else false
109
     */
110 7
    private function makeResources($paths)
111
    {
112 7
        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...
113 5
            $resources = array();
114
115 5
            foreach ($paths as $path) {
116 5
                $resources[] = $path;
117
            }
118
119 5
            return $resources;
120
        }
121
122 2
        return false;
123
    }
124
}
125