Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class FunctionCommentSniff extends PEARFunctionCommentSniff
*/
public $skipIfInheritdoc = false;

/**
* Whether to use short forms of type keywords.
*
* @var boolean
*/
public $useShortTypes = false;

/**
* The current PHP version.
*
Expand Down Expand Up @@ -88,7 +95,7 @@ protected function processReturn(File $phpcsFile, int $stackPtr, int $commentSta
$typeNames = explode('|', $returnType);
$suggestedNames = [];
foreach ($typeNames as $typeName) {
$suggestedName = Common::suggestType($typeName);
$suggestedName = Common::suggestType($typeName, $this->useShortTypes);
if (in_array($suggestedName, $suggestedNames, true) === false) {
$suggestedNames[] = $suggestedName;
}
Expand Down Expand Up @@ -419,7 +426,7 @@ protected function processParams(File $phpcsFile, int $stackPtr, int $commentSta
$typeName = substr($typeName, 1);
}

$suggestedName = Common::suggestType($typeName);
$suggestedName = Common::suggestType($typeName, $this->useShortTypes);
$suggestedTypeNames[] = $suggestedName;

if (count($typeNames) > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
class VariableCommentSniff extends AbstractVariableSniff
{

/**
* Whether to use short forms of type keywords.
*
* @var boolean
*/
public $useShortTypes = false;


/**
* Only listen to variables within OO scopes.
Expand Down Expand Up @@ -149,7 +156,7 @@ public function processMemberVar(File $phpcsFile, int $stackPtr)
$typeNames = explode('|', $varType);
$suggestedNames = [];
foreach ($typeNames as $typeName) {
$suggestedName = Common::suggestType($typeName);
$suggestedName = Common::suggestType($typeName, $this->useShortTypes);
if (in_array($suggestedName, $suggestedNames, true) === false) {
$suggestedNames[] = $suggestedName;
}
Expand Down
33 changes: 33 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.3.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

// phpcs:set Squiz.Commenting.FunctionComment useShortTypes false

/**
* Type check for function with both long and short types.
*
* @param bool $a1 Comment here.
* @param boolean $a2 Comment here.
* @param int $a3 Comment here.
* @param integer $a4 Comment here.
*
* @return void
*/
function mixedLongAndShortUseLong(bool $a1, bool $a2, int $a3, int $a4)
{
}//end mixedLongAndShortUseLong()

// phpcs:set Squiz.Commenting.FunctionComment useShortTypes true

/**
* Type check for function with both long and short types.
*
* @param bool $a1 Comment here.
* @param boolean $a2 Comment here.
* @param int $a3 Comment here.
* @param integer $a4 Comment here.
*
* @return void
*/
function mixedLongAndShortUseShort(bool $a1, bool $a2, int $a3, int $a4)
{
}//end mixedLongAndShortUseShort()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

// phpcs:set Squiz.Commenting.FunctionComment useShortTypes false

/**
* Type check for function with both long and short types.
*
* @param boolean $a1 Comment here.
* @param boolean $a2 Comment here.
* @param integer $a3 Comment here.
* @param integer $a4 Comment here.
*
* @return void
*/
function mixedLongAndShortUseLong(bool $a1, bool $a2, int $a3, int $a4)
{
}//end mixedLongAndShortUseLong()

// phpcs:set Squiz.Commenting.FunctionComment useShortTypes true

/**
* Type check for function with both long and short types.
*
* @param bool $a1 Comment here.
* @param bool $a2 Comment here.
* @param int $a3 Comment here.
* @param int $a4 Comment here.
*
* @return void
*/
function mixedLongAndShortUseShort(bool $a1, bool $a2, int $a3, int $a4)
{
}//end mixedLongAndShortUseShort()
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ public function getErrorList($testFile = '')
8 => 1,
];

case 'FunctionCommentUnitTest.3.inc':
return [
8 => 1,
10 => 1,
25 => 1,
27 => 1,
];

default:
return [];
}
Expand Down
51 changes: 51 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

// phpcs:set Squiz.Commenting.VariableComment useShortTypes false

class UsingLongTypes
{
/**
* @var bool
*/
public $typeBool;

/**
* @var boolean
*/
public $typeBoolean;

/**
* @var int
*/
public $typeInt;

/**
* @var integer
*/
public $typeInteger;
}

// phpcs:set Squiz.Commenting.VariableComment useShortTypes true

class UsingShortTypes
{
/**
* @var bool
*/
public $typeBool;

/**
* @var boolean
*/
public $typeBoolean;

/**
* @var int
*/
public $typeInt;

/**
* @var integer
*/
public $typeInteger;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

// phpcs:set Squiz.Commenting.VariableComment useShortTypes false

class UsingLongTypes
{
/**
* @var boolean
*/
public $typeBool;

/**
* @var boolean
*/
public $typeBoolean;

/**
* @var integer
*/
public $typeInt;

/**
* @var integer
*/
public $typeInteger;
}

// phpcs:set Squiz.Commenting.VariableComment useShortTypes true

class UsingShortTypes
{
/**
* @var bool
*/
public $typeBool;

/**
* @var bool
*/
public $typeBoolean;

/**
* @var int
*/
public $typeInt;

/**
* @var int
*/
public $typeInteger;
}
115 changes: 70 additions & 45 deletions src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,63 @@ final class VariableCommentUnitTest extends AbstractSniffTestCase
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the test file being tested.
*
* @return array<int, int>
*/
public function getErrorList()
public function getErrorList($testFile = '')
{
return [
21 => 1,
24 => 1,
56 => 1,
64 => 1,
73 => 1,
84 => 1,
130 => 1,
136 => 1,
144 => 1,
152 => 1,
160 => 1,
168 => 1,
176 => 1,
184 => 1,
192 => 1,
200 => 1,
208 => 1,
216 => 1,
224 => 1,
232 => 1,
240 => 1,
248 => 1,
256 => 1,
264 => 1,
272 => 1,
280 => 1,
290 => 1,
294 => 1,
311 => 1,
336 => 1,
361 => 1,
364 => 1,
399 => 1,
403 => 1,
457 => 1,
];
switch ($testFile) {
case 'VariableCommentUnitTest.1.inc':
return [
21 => 1,
24 => 1,
56 => 1,
64 => 1,
73 => 1,
84 => 1,
130 => 1,
136 => 1,
144 => 1,
152 => 1,
160 => 1,
168 => 1,
176 => 1,
184 => 1,
192 => 1,
200 => 1,
208 => 1,
216 => 1,
224 => 1,
232 => 1,
240 => 1,
248 => 1,
256 => 1,
264 => 1,
272 => 1,
280 => 1,
290 => 1,
294 => 1,
311 => 1,
336 => 1,
361 => 1,
364 => 1,
399 => 1,
403 => 1,
457 => 1,
];

case 'VariableCommentUnitTest.2.inc':
return [
8 => 1,
18 => 1,
38 => 1,
48 => 1,
];

default:
return [];
}
}


Expand All @@ -77,15 +93,24 @@ public function getErrorList()
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @param string $testFile The name of the test file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
public function getWarningList($testFile = '')
{
return [
93 => 1,
494 => 1,
495 => 1,
496 => 1,
];
switch ($testFile) {
case 'VariableCommentUnitTest.1.inc':

return [
93 => 1,
494 => 1,
495 => 1,
496 => 1,
];

default:
return [];
}
}
}
Loading
Loading