BaseCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllFilesInDir() 0 11 2
A blacklisted() 0 4 2
1
<?php
2
3
namespace Juddling\RouteChecker\Commands;
4
5
use Illuminate\Console\Command;
6
use RecursiveDirectoryIterator;
7
use RecursiveIteratorIterator;
8
use RegexIterator;
9
10
class BaseCommand extends Command
11
{
12
    protected function getAllFilesInDir($directory, $fileExtension)
13
    {
14
        $directory = realpath($directory);
15
        $it = new RecursiveDirectoryIterator($directory);
16
        $it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::LEAVES_ONLY);
17
        $it = new RegexIterator($it, '(\.' . preg_quote($fileExtension) . '$)');
18
19
        foreach ($it as $file) {
20
            /** @var \SplFileObject $file */
21
            $filepath = $file->getRealPath();
22
            yield $filepath;
23
        }
24
    }
25
26
    /**
27
     * Given a file path, returns if this file should be parsed.
28
     *
29
     * @param $file
30
     * @return bool
31
     */
32
    protected function blacklisted($file): bool
33
    {
34
        return strpos($file, 'vendor/')
35
            || strpos($file, 'storage/framework/views/');
36
    }
37
}
38