Completed
Push — master ( 783cc3...112ad4 )
by
unknown
04:56 queued 03:47
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 Spatie\BladeX\Exceptions\CouldNotRegisterComponent;
8
9
class RegularDirectory extends ComponentDirectory
10
{
11
    public function __construct(string $viewDirectory)
12
    {
13
        $this->viewDirectory = Str::before($viewDirectory, '.*');
14
    }
15
16
    public function getAbsoluteDirectory(): string
17
    {
18
        $viewPath = str_replace('.', '/', $this->viewDirectory);
19
20
        $absoluteDirectory = collect(View::getFinder()->getPaths())
21
            ->map(function (string $path) use ($viewPath) {
22
                return realpath($path.'/'.$viewPath);
23
            })
24
            ->filter()
25
            ->first();
26
27
        if (! $absoluteDirectory) {
28
            throw CouldNotRegisterComponent::viewPathNotFound($viewPath);
29
        }
30
31
        return $absoluteDirectory;
32
    }
33
}
34