Skip to content

Commit

Permalink
Making sure var sniffs work with types; only Squiz.Commenting.Variabl…
Browse files Browse the repository at this point in the history
…eComment needed a change (ref squizlabs#2517)
  • Loading branch information
gsherwood committed May 27, 2019
1 parent e988f62 commit beeb36f
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 17 deletions.
21 changes: 21 additions & 0 deletions src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,24 @@ class ABC {
$propE;
static private /*comment*/ $propF;
}

class MyClass
{
public string $var = null;
protected ?Folder\ClassName $var = null;

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

private int $_var = null;

public $foo, $bar, $var = null;
public ?string $foo,
$bar,
$var = null;

protected
array
$foo,
$bar;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,24 @@ class ABC {
$propE;
private static /*comment*/ $propF;
}

class MyClass
{
public string $var = null;
protected ?Folder\ClassName $var = null;

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

private int $_var = null;

public $foo, $bar, $var = null;
public ?string $foo,
$bar,
$var = null;

protected
array
$foo,
$bar;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function getErrorList()
38 => 1,
41 => 1,
42 => 1,
50 => 2,
51 => 1,
55 => 1,
56 => 1,
62 => 1,
];

}//end getErrorList()
Expand All @@ -55,6 +60,7 @@ public function getWarningList()
13 => 1,
14 => 1,
15 => 1,
53 => 1,
];

}//end getWarningList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
T_VAR,
T_STATIC,
T_WHITESPACE,
T_STRING,
T_NS_SEPARATOR,
T_NULLABLE,
];

$commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function processVariable(File $phpcsFile, $stackPtr)
// check the main part of the variable name.
$originalVarName = $varName;
if (substr($varName, 0, 1) === '_') {
$objOperator = $phpcsFile->findPrevious([T_WHITESPACE], ($stackPtr - 1), null, true);
$objOperator = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if ($tokens[$objOperator]['code'] === T_DOUBLE_COLON) {
// The variable lives within a class, and is referenced like
// this: MyClass::$_variable, so we don't know its scope.
Expand Down
22 changes: 21 additions & 1 deletion src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ class Foo
*
* @var array
*/
public static $variableName = array();
public static array $variableName = array();

}

class Foo
{

/**
* Short description of the member variable.
*
* @var array
*/
public array $variableName = array();


// Not "/**" style comment.
//
// @var string
private ?Folder\ClassName $_incorrectCommentStyle = null;


var int $noComment = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ class Foo
*
* @var array
*/
public static $variableName = array();
public static array $variableName = array();

}

class Foo
{

/**
* Short description of the member variable.
*
* @var array
*/
public array $variableName = array();


// Not "/**" style comment.
//
// @var string
private ?Folder\ClassName $_incorrectCommentStyle = null;


var int $noComment = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function getErrorList()
294 => 1,
311 => 1,
336 => 1,
361 => 1,
364 => 1,
];

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class MyClass
$_varName = 'hello';

public $varName = 'hello';
public $var_name = 'hello';
public bool $var_name = false;
public $varname = 'hello';
public $_varName = 'hello';

protected $varName = 'hello';
protected $var_name = 'hello';
protected string $var_name = 'hello';
protected $varname = 'hello';
protected $_varName = 'hello';
protected ?string $_varName = 'hello';

private $_varName = 'hello';
private $_var_name = 'hello';
private $_varname = 'hello';
private int $_varname = 1;
private $varName = 'hello';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Standards/Squiz/Tests/Scope/MemberVarScopeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class MyClass
{
private $var1 = null;
protected $var2 = null;
protected ?int $var2 = null;
public $var3 = null;
$var4 = null;
}
Expand Down Expand Up @@ -54,7 +54,7 @@ class MyClass {
$var = null;
}

public $mCounter, $mSearchUser, $mSearchPeriodStart, $mSearchPeriodEnd,
public string $mCounter, $mSearchUser, $mSearchPeriodStart, $mSearchPeriodEnd,
$mTestFilter;

protected $mCounter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class MyClass
public $var1 = 'value';


public $var2 = 'value';
public ?int $var2 = 'value';

public $var3 = 'value';

Expand All @@ -17,7 +17,7 @@ interface MyInterface
public $var1 = 'value';


public $var2 = 'value';
public ?Folder\ClassName $var2 = 'value';

protected $var3 = 'value';
}//end interface
Expand All @@ -27,9 +27,9 @@ class MyClass
{


public $var1 = 'value';
public string $var1 = 'value';

private $var2 = 'value';
private string $var2 = 'value';


protected $var3 = 'value';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class MyClass

public $var1 = 'value';

public $var2 = 'value';
public ?int $var2 = 'value';

public $var3 = 'value';

Expand All @@ -16,7 +16,7 @@ interface MyInterface

public $var1 = 'value';

public $var2 = 'value';
public ?Folder\ClassName $var2 = 'value';

protected $var3 = 'value';
}//end interface
Expand All @@ -25,9 +25,9 @@ interface MyInterface
class MyClass
{

public $var1 = 'value';
public string $var1 = 'value';

private $var2 = 'value';
private string $var2 = 'value';

protected $var3 = 'value';

Expand Down

0 comments on commit beeb36f

Please sign in to comment.