NamespacedDirectory::getViewName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
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\Facades\View;
6
use Illuminate\Support\Str;
7
use Spatie\BladeX\Exceptions\CouldNotRegisterComponent;
8
use Symfony\Component\Finder\SplFileInfo;
9
10
class NamespacedDirectory extends ComponentDirectory
11
{
12
    /** @var string */
13
    protected $namespace;
14
15
    public function __construct(string $viewDirectory, bool $includeSubdirectories)
16
    {
17
        [$this->namespace, $viewDirectory] = explode('::', $viewDirectory);
18
        $this->viewDirectory = trim(Str::before($viewDirectory, '*'), '.');
19
        $this->includeSubdirectories = $includeSubdirectories;
20
    }
21
22
    public function getAbsoluteDirectory(): string
23
    {
24
        $viewPath = str_replace('.', '/', $this->viewDirectory);
25
26
        $absoluteDirectory = View::getFinder()->getHints()[$this->namespace][0] ?? null;
27
28
        if (! $absoluteDirectory) {
29
            throw CouldNotRegisterComponent::viewPathNotFound($viewPath);
30
        }
31
32
        return $viewPath ? "{$absoluteDirectory}/{$viewPath}" : $absoluteDirectory;
33
    }
34
35
    public function getViewName(SplFileInfo $viewFile): string
36
    {
37
        return "{$this->namespace}::".parent::getViewName($viewFile);
38
    }
39
}
40