Skip to content

Commit

Permalink
feat(PropertyDeclaration): Add fixed for 'var' keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi committed Jan 2, 2025
1 parent b43e1d8 commit 94874db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)

if ($tokens[$prev]['code'] === T_VAR) {
$error = 'The var keyword must not be used to declare a property';
$phpcsFile->addError($error, $stackPtr, 'VarUsed');
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'VarUsed');
if ($fix === true) {
$phpcsFile->fixer->replaceToken($prev, 'public');
}
}

$next = $phpcsFile->findNext([T_VARIABLE, T_SEMICOLON], ($stackPtr + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class MyClass
private $var = null;
$var = null;

var $var = null;
public $var = null;
static $var = null;
public var $var = null; // Parse error.
public public $var = null; // Parse error.

public $_var = null;
protected $_var = null;
Expand Down Expand Up @@ -46,7 +46,7 @@ class MyClass
public string $var = null;
protected ?Folder\ClassName $var = null;

var int $var = null;
public int $var = null;
static int $var = null;

private int $_var = null;
Expand Down

0 comments on commit 94874db

Please sign in to comment.