Completed
Pull Request — master (#84)
by Tom
02:00
created

RegularDirectory::getViewName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\BladeX\ComponentDirectory;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\Facades\View;
7
use Symfony\Component\Finder\SplFileInfo;
8
use Spatie\BladeX\Exceptions\CouldNotRegisterComponent;
9
10
class RegularDirectory extends ComponentDirectory
11
{
12
    public function __construct(string $viewDirectory)
13
    {
14
        $this->viewDirectory = Str::before($viewDirectory, '.*');
15
    }
16
17
    public function getAbsoluteDirectory(): string
18
    {
19
        $viewPath = str_replace('.', '/', $this->viewDirectory);
20
21
        $absoluteDirectory = collect(View::getFinder()->getPaths())
22
            ->map(function (string $path) use ($viewPath) {
23
                return realpath($path.'/'.$viewPath);
24
            })
25
            ->filter()
26
            ->first();
27
28
        if (! $absoluteDirectory) {
29
            throw CouldNotRegisterComponent::viewPathNotFound($viewPath);
30
        }
31
32
        return $absoluteDirectory;
33
    }
34
}
35