Completed
Pull Request — master (#48)
by James
01:23
created

SuggestImportSolution::getRunButtonText()   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
7
class SuggestImportSolution implements RunnableSolution
8
{
9
    /** @var string */
10
    protected $class;
11
12
    public function __construct(string $class = null)
13
    {
14
        $this->class = $class;
15
    }
16
17
    public function getSolutionTitle(): string
18
    {
19
        return 'A class import is missing';
20
    }
21
22
    public function getSolutionDescription(): string
23
    {
24
        return '';
25
    }
26
27
    public function getSolutionActionDescription(): string
28
    {
29
        $output = [
30
            'You have a missing class import. Try importing this class: `'.$this->class.'`.',
31
        ];
32
33
        return implode(PHP_EOL, $output);
34
    }
35
36
    public function getRunButtonText(): string
37
    {
38
        return 'Import class';
39
    }
40
41
    public function getDocumentationLinks(): array
42
    {
43
        return [];
44
    }
45
46
    public function getRunParameters(): array
47
    {
48
        return [
49
            'class' => $this->class,
50
        ];
51
    }
52
53
    public function isRunnable(array $parameters = [])
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        return false;
56
        //return $this->makeOptional($this->getRunParameters()) !== false;
57
    }
58
59
    public function run(array $parameters = [])
60
    {
61
        $output = $this->importClass($parameters);
62
        if ($output !== false) {
63
            file_put_contents($parameters['viewFile'], $output);
64
        }
65
    }
66
67
    public function importClass(array $parameters = [])
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69
        return false;
70
        // $originalContents = file_get_contents($parameters['viewFile']);
71
        // $newContents = str_replace('$'.$parameters['variableName'], '$'.$parameters['variableName']." ?? ''", $originalContents);
72
        // // Compile blade, tokenize
73
        // $originalTokens = token_get_all(Blade::compileString($originalContents));
74
        // $newTokens = token_get_all(Blade::compileString($newContents));
75
        // // Generate what we expect the tokens to be after we change the blade file
76
        // $expectedTokens = [];
77
        // foreach ($originalTokens as $key => $token) {
78
        //     $expectedTokens[] = $token;
79
        //     if ($token[0] === T_VARIABLE && $token[1] === '$'.$parameters['variableName']) {
80
        //         $expectedTokens[] = [T_WHITESPACE, ' ', $token[2]];
81
        //         $expectedTokens[] = [T_COALESCE, '??', $token[2]];
82
        //         $expectedTokens[] = [T_WHITESPACE, ' ', $token[2]];
83
        //         $expectedTokens[] = [T_CONSTANT_ENCAPSED_STRING, "''", $token[2]];
84
        //     }
85
        // }
86
        // if ($expectedTokens !== $newTokens) {
87
        //     return false;
88
        // }
89
        // return $newContents;
90
    }
91
}
92