for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Facade\Ignition\Solutions;
use Facade\IgnitionContracts\RunnableSolution;
use Facade\IgnitionContracts\Solution;
use Illuminate\Support\Facades\Blade;
class SuggestCorrectVariableNameSolution implements Solution
{
/** @var string */
private $variableName;
private $viewFile;
public function __construct($variableName = null, $viewFile = null, $suggested = null)
$this->variableName = $variableName;
$this->viewFile = $viewFile;
$this->suggested = $suggested;
suggested
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;
}
public function getSolutionTitle(): string
return 'Possible typo $'.$this->variableName;
public function getDocumentationLinks(): array
return [];
public function getSolutionDescription(): string
$path = str_replace(base_path().'/', '', $this->viewFile);
$path
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.
$myVar
$higher
return "Did you mean `$$this->suggested`?";
public function isRunnable(): bool
return false;
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: