1 | <?php |
||
8 | class SuggestCorrectVariableNameSolution implements RunnableSolution |
||
9 | { |
||
10 | /** @var string */ |
||
11 | private $variableName; |
||
12 | |||
13 | /** @var string */ |
||
14 | private $viewFile; |
||
15 | |||
16 | public function __construct($variableName = null, $viewFile = null, $suggested = null) |
||
17 | { |
||
18 | $this->variableName = $variableName; |
||
19 | $this->viewFile = $viewFile; |
||
20 | $this->suggested = $suggested; |
||
|
|||
21 | } |
||
22 | |||
23 | public function getSolutionTitle(): string |
||
24 | { |
||
25 | return 'Possible typo $'.$this->variableName; |
||
26 | } |
||
27 | |||
28 | public function getDocumentationLinks(): array |
||
29 | { |
||
30 | return []; |
||
31 | } |
||
32 | |||
33 | public function getSolutionActionDescription(): string |
||
34 | { |
||
35 | $path = str_replace(base_path().'/', '', $this->viewFile); |
||
36 | |||
37 | return "Did you mean `$$this->suggested`?"; |
||
38 | } |
||
39 | |||
40 | public function getRunButtonText(): string |
||
44 | |||
45 | public function getSolutionDescription(): string |
||
49 | |||
50 | public function getRunParameters(): array |
||
58 | |||
59 | public function isRunnable(array $parameters = []): bool |
||
63 | |||
64 | public function run(array $parameters = []): void |
||
65 | { |
||
66 | $output = $this->fixTypo($parameters); |
||
67 | if ($output === false) { |
||
73 | |||
74 | protected function fixTypo(array $parameters = []) |
||
94 | |||
95 | protected function isAlphaNumericWithUnderscore(string $input): bool |
||
99 | |||
100 | protected function generateExpectedTokens(array $originalTokens, string $variableName, string $suggested): array |
||
111 | } |
||
112 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: