RegularDirectory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAbsoluteDirectory() 0 17 2
A __construct() 0 5 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
9
class RegularDirectory extends ComponentDirectory
10
{
11
    public function __construct(string $viewDirectory, bool $includeSubdirectories)
12
    {
13
        $this->viewDirectory = Str::before($viewDirectory, '.*');
14
        $this->includeSubdirectories = $includeSubdirectories;
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