LaravelPaths   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 18
lcom 0
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A seeders() 0 6 2
A factoryDirs() 0 8 2
A migrationDirs() 0 16 3
A isIgnored() 0 16 5
A bladeFilePaths() 0 20 5
A getNamespacedPaths() 0 7 1
1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\LaravelPaths;
4
5
use Illuminate\Database\Eloquent\Factory;
6
use Illuminate\Support\Facades\View;
7
use Illuminate\Support\Str;
8
use Symfony\Component\Finder\Finder;
9
10
class LaravelPaths
11
{
12
    public static function seeders()
13
    {
14
        $dir = app()->databasePath('seeds');
15
16
        return is_dir($dir) ? $dir : null;
17
    }
18
19
    public static function factoryDirs()
20
    {
21
        try {
22
            return app()->make(Factory::class)->loadedPaths;
23
        } catch (\Throwable $e) {
24
            return [];
25
        }
26
    }
27
28
    public static function migrationDirs()
29
    {
30
        // normalize the migration paths
31
        $migrationDirs = [];
32
33
        foreach (app('migrator')->paths() as $path) {
34
            // Excludes the migrations within "vendor" folder:
35
            if (! Str::startsWith($path, [base_path('vendor')])) {
36
                $migrationDirs[] = FilePath::normalize($path);
37
            }
38
        }
39
40
        $migrationDirs[] = app()->databasePath().DIRECTORY_SEPARATOR.'migrations';
41
42
        return $migrationDirs;
43
    }
44
45
    /**
46
     * Check given path should be ignored.
47
     *
48
     * @param string $path
49
     * @return bool
50
     */
51
    public static function isIgnored($path)
52
    {
53
        $ignorePatterns = config('microscope.ignore');
54
55
        if (! $ignorePatterns || ! is_array($ignorePatterns)) {
56
            return false;
57
        }
58
59
        foreach ($ignorePatterns as $ignorePattern) {
60
            if (Str::is(base_path($ignorePattern), $path)) {
61
                return true;
62
            }
63
        }
64
65
        return false;
66
    }
67
68
    public static function bladeFilePaths()
69
    {
70
        $bladeFiles = [];
71
        $hints = self::getNamespacedPaths();
72
        $hints['1'] = View::getFinder()->getPaths();
73
74
        foreach ($hints as $paths) {
75
            foreach ($paths as $path) {
76
                $files = is_dir($path) ? Finder::create()->name('*.blade.php')->files()->in($path) : [];
77
                foreach ($files as $blade) {
78
                    /**
79
                     * @var \Symfony\Component\Finder\SplFileInfo $blade
80
                     */
81
                    $bladeFiles[] = $blade->getRealPath();
82
                }
83
            }
84
        }
85
86
        return $bladeFiles;
87
    }
88
89
    private static function getNamespacedPaths()
90
    {
91
        $hints = View::getFinder()->getHints();
92
        unset($hints['notifications'], $hints['pagination']);
93
94
        return $hints;
95
    }
96
}
97