Completed
Push — master ( 38e1b1...e6db1d )
by Freek
01:33
created

SuggestCorrectVariableNameSolution::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Facade\Ignition\Solutions;
4
5
use Facade\IgnitionContracts\RunnableSolution;
6
use Facade\IgnitionContracts\Solution;
7
use Illuminate\Support\Facades\Blade;
8
9
class SuggestCorrectVariableNameSolution implements Solution
10
{
11
    /** @var string */
12
    private $variableName;
13
14
    /** @var string */
15
    private $viewFile;
16
17
    public function __construct($variableName = null, $viewFile = null, $suggested = null)
18
    {
19
        $this->variableName = $variableName;
20
        $this->viewFile = $viewFile;
21
        $this->suggested = $suggested;
0 ignored issues
show
Bug introduced by
The property suggested does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
    }
23
24
    public function getSolutionTitle(): string
25
    {
26
        return 'Possible typo $'.$this->variableName;
27
    }
28
29
    public function getDocumentationLinks(): array
30
    {
31
        return [];
32
    }
33
34
    public function getSolutionDescription(): string
35
    {
36
        $path = str_replace(base_path().'/', '', $this->viewFile);
0 ignored issues
show
Unused Code introduced by
$path is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
37
38
        return "Did you mean `$$this->suggested`?";
39
    }
40
41
    public function isRunnable(): bool
42
    {
43
        return false;
44
    }
45
}
46