Completed
Push — master ( 949f21...8711d2 )
by Iman
01:33
created

LaravelPaths::seeders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 6
rs 10
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\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
        if (! $ignorePatterns || ! is_array($ignorePatterns)) {
55
            return false;
56
        }
57
58
        foreach ($ignorePatterns as $ignorePattern) {
59
            if (Str::is(base_path($ignorePattern), $path)) {
60
                return true;
61
            }
62
        }
63
64
        return false;
65
    }
66
67
    public static function bladeFilePaths()
68
    {
69
        $bladeFiles = [];
70
        $hints = self::getNamespacedPaths();
71
        $hints['1'] = View::getFinder()->getPaths();
72
73
        foreach ($hints as $paths) {
74
            foreach ($paths as $path) {
75
                $files = is_dir($path) ? Finder::create()->name('*.blade.php')->files()->in($path) : [];
76
                foreach ($files as $blade) {
77
                    /**
78
                     * @var \Symfony\Component\Finder\SplFileInfo $blade
79
                     */
80
                    $bladeFiles[] = $blade->getRealPath();
81
                }
82
            }
83
        }
84
85
        return $bladeFiles;
86
    }
87
88
    private static function getNamespacedPaths()
89
    {
90
        $hints = View::getFinder()->getHints();
91
        unset($hints['notifications'], $hints['pagination']);
92
93
        return $hints;
94
    }
95
}
96