Completed
Pull Request — master (#42)
by James
01:14
created

CreateViewFileSolution   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 53
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSolutionTitle() 0 4 1
A getDocumentationLinks() 0 4 1
A getSolutionActionDescription() 0 4 1
A getRunButtonText() 0 4 1
A getSolutionDescription() 0 4 1
A getRunParameters() 0 6 1
A run() 0 11 1
1
<?php
2
3
namespace Facade\Ignition\Solutions;
4
5
use Illuminate\Support\Facades\Blade;
6
use Symfony\Component\Filesystem\Filesystem;
7
use Facade\IgnitionContracts\RunnableSolution;
8
use Illuminate\Support\Facades\View;
9
10
class CreateViewFileSolution implements RunnableSolution
11
{
12
    private $viewName;
13
14
    public function __construct($viewName = null)
15
    {
16
        $this->viewName = $viewName;
17
    }
18
19
    public function getSolutionTitle(): string
20
    {
21
        return $this->viewName . ' was not found.';
22
    }
23
24
    public function getDocumentationLinks(): array
25
    {
26
        return [];
27
    }
28
29
    public function getSolutionActionDescription(): string
30
    {
31
        return 'Are you sure the view exist and is a `.blade.php` file?';
32
    }
33
34
    public function getRunButtonText(): string
35
    {
36
        return 'Create file';
37
    }
38
39
    public function getSolutionDescription(): string
40
    {
41
        return '';
42
    }
43
44
    public function getRunParameters(): array
45
    {
46
        return [
47
            'viewName' => $this->viewName,
48
        ];
49
    }
50
51
    public function run(array $parameters = [])
52
    {
53
        $parts = explode('.', $parameters['viewName']);
54
        $file = array_pop($parts);
55
        $path = implode('/', $parts);
56
        $fileViewFinder = View::getFinder();
57
58
        $filesystem = new Filesystem();
59
        $filesystem->mkdir($fileViewFinder->getPaths()[0] . '/' . $path . '/');
60
        touch($fileViewFinder->getPaths()[0] . '/' . $path . '/' . $file . '.blade.php');
61
    }
62
}
63