Completed
Pull Request — master (#76)
by amir
01:25
created

LaravelPaths::isIgnored()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 1
dl 0
loc 15
rs 9.4555
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\LaravelPaths;
4
5
use Illuminate\Database\Eloquent\Factory;
6
use Illuminate\Support\Str;
7
use Imanghafoori\LaravelMicroscope\Analyzers\FilePath;
8
9
class LaravelPaths
10
{
11
    public static function factoryDirs()
12
    {
13
        return app()->make(Factory::class)->loadedPaths;
14
    }
15
16
    public static function migrationDirs()
17
    {
18
        // normalize the migration paths
19
        $migrationDirs = [];
20
21
        foreach (app('migrator')->paths() as $path) {
22
            // Excludes the migrations within "vendor" folder:
23
            if (! Str::startsWith($path, [base_path('vendor')])) {
24
                $migrationDirs[] = FilePath::normalize($path);
25
            }
26
        }
27
28
        $migrationDirs[] = app()->databasePath().DIRECTORY_SEPARATOR.'migrations';
29
30
        return $migrationDirs;
31
    }
32
33
    /**
34
     * Check given path should be ignored.
35
     *
36
     * @param string $path
37
     * @return boolean
38
     */
39
    public static function isIgnored($path)
40
    {
41
        $ignorePatterns = config('microscope.ignore');
42
        if (is_array($ignorePatterns) == false || is_string($path) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
43
            return false;
44
        }
45
46
        foreach ($ignorePatterns as $ignorePattern) {
47
            if (fnmatch(rtrim(base_path(), '\\/').'/'.ltrim($ignorePattern, '\\/'), $path)) {
48
                return true;
49
            }
50
        }
51
52
        return false;
53
    }
54
}
55