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

getSolutionActionDescription()   A

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