Skip to content

Commit

Permalink
Fix up PHP8.1 (#33)
Browse files Browse the repository at this point in the history
* Fix up PHP 8.1
  • Loading branch information
dereuromark committed Oct 15, 2023
1 parent 34ff6ed commit bf42618
Show file tree
Hide file tree
Showing 27 changed files with 188 additions and 168 deletions.
4 changes: 2 additions & 2 deletions PSR2R/Sniffs/Commenting/DocBlockNoEmptySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) {
*
* @return void
*/
protected function assertNonEmptyDocBlock(File $phpcsFile, $stackPtr, $endIndex) {
protected function assertNonEmptyDocBlock(File $phpcsFile, int $stackPtr, int $endIndex): void {
$nextIndex = $phpcsFile->findNext([T_WHITESPACE, T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR], $stackPtr + 1, $endIndex - 1, true);
if ($nextIndex) {
return;
Expand All @@ -63,7 +63,7 @@ protected function assertNonEmptyDocBlock(File $phpcsFile, $stackPtr, $endIndex)
*
* @return void
*/
protected function assertNoEmptyTag(File $phpcsFile, $stackPtr, $endIndex) {
protected function assertNoEmptyTag(File $phpcsFile, int $stackPtr, int $endIndex): void {
$tokens = $phpcsFile->getTokens();

$index = $stackPtr;
Expand Down
2 changes: 1 addition & 1 deletion PSR2R/Sniffs/Commenting/DocBlockParamSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function process(File $phpCsFile, $stackPointer): void {
*
* @return array
*/
private function getMethodSignature(File $phpCsFile, $stackPtr) {
private function getMethodSignature(File $phpCsFile, int $stackPtr): array {
$tokens = $phpCsFile->getTokens();

$startIndex = $phpCsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1);
Expand Down
2 changes: 1 addition & 1 deletion PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function isNonChainable(array $tokens, int $stackPointer): bool {
*
* @return void
*/
protected function fixParts(File $phpCsFile, $classNameIndex, array $parts, $appendix) {
protected function fixParts(File $phpCsFile, int $classNameIndex, array $parts, string $appendix): void {
$result = [];
foreach ($parts as $key => $part) {
if ($part !== 'self') {
Expand Down
2 changes: 1 addition & 1 deletion PSR2R/Sniffs/Commenting/DocBlockShortTypeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function process(File $phpCsFile, $stackPointer): void {
*
* @return void
*/
protected function fixParts(File $phpCsFile, $classNameIndex, array $parts, $appendix) {
protected function fixParts(File $phpCsFile, int $classNameIndex, array $parts, string $appendix): void {
$mapping = [
'boolean' => 'bool',
'integer' => 'int',
Expand Down
10 changes: 5 additions & 5 deletions PSR2R/Sniffs/Commenting/DocBlockTagTypesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
/**
* @var array
*/
protected static $whitelistedTags = [
protected static array $whitelistedTags = [
'@api',
'@author',
'@copyright',
Expand Down Expand Up @@ -92,7 +92,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
/**
* @var array
*/
protected static $blacklistedTags = [
protected static array $blacklistedTags = [
'@package',
'@subpackage',
'@global',
Expand All @@ -105,7 +105,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
/**
* @var array
*/
protected static $mapping = [
protected static array $mapping = [
'@type' => '@var',
'@overwrite' => '@override',
'@inheritdoc' => '@inheritDoc',
Expand All @@ -121,7 +121,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
*
* @var string
*/
public $whitelist = '';
public string $whitelist = '';

/**
* @inheritDoc
Expand Down Expand Up @@ -196,7 +196,7 @@ public function process(File $phpcsFile, $stackPtr) {
/**
* @return void
*/
protected function prepareWhitelist() {
protected function prepareWhitelist(): void {
if (!empty($this->whitelist)) {
$whitelist = explode(',', $this->whitelist);
foreach ($whitelist as $tag) {
Expand Down
2 changes: 1 addition & 1 deletion PSR2R/Sniffs/Commenting/DocCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DocCommentSniff extends AbstractSniff {
*
* @var array
*/
public $supportedTokenizers = [
public array $supportedTokenizers = [
'PHP',
'JS',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public function process(File $phpCsFile, $stackPointer): void {
/**
* @param \PHP_CodeSniffer\Files\File $phpCsFile
* @param int $index
* @param int $limit
* @param int|null $limit
*
* @return int|null
*/
protected function detectRightEnd(File $phpCsFile, $index, $limit = 0) {
protected function detectRightEnd(File $phpCsFile, int $index, ?int $limit = 0): ?int {
$tokens = $phpCsFile->getTokens();

$rightEndIndex = $index;
Expand Down Expand Up @@ -163,12 +163,12 @@ protected function detectRightEnd(File $phpCsFile, $index, $limit = 0) {
* @return void
*/
protected function applyFix(File $phpCsFile,
$index,
$leftIndexStart,
$leftIndexEnd,
$rightIndexStart,
$rightIndexEnd,
) {
int $index,
int $leftIndexStart,
int $leftIndexEnd,
int $rightIndexStart,
int $rightIndexEnd,
): void {
$tokens = $phpCsFile->getTokens();

$token = $tokens[$index];
Expand Down Expand Up @@ -200,7 +200,7 @@ protected function applyFix(File $phpCsFile,
*
* @return string
*/
protected function getComparisonValue(array $token) {
protected function getComparisonValue(array $token): string {
$comparisonIndexValue = $token['content'];
$operatorsToMap = [T_GREATER_THAN, T_LESS_THAN, T_IS_GREATER_OR_EQUAL, T_IS_SMALLER_OR_EQUAL];
if (in_array($token['code'], $operatorsToMap, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class ControlStructureSpacingSniff implements Sniff {
/**
* How many spaces should follow the opening bracket.
*
* @var int
*/
public $requiredSpacesAfterOpen = 0;
public int $requiredSpacesAfterOpen = 0;

/**
* @inheritDoc
Expand All @@ -57,9 +56,8 @@ public function register(): array {
/**
* How many spaces should precede the closing bracket.
*
* @var int
*/
public $requiredSpacesBeforeClose = 0;
public int $requiredSpacesBeforeClose = 0;

/**
* @inheritDoc
Expand Down
10 changes: 5 additions & 5 deletions PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function process(File $phpcsFile, $stackPtr) {
/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
*
*
* @return void
*/
protected function checkMethodCalls(File $phpcsFile, $stackPtr) {
protected function checkMethodCalls(File $phpcsFile, int $stackPtr): void {
$tokens = $phpcsFile->getTokens();

$openingBraceIndex = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1, $stackPtr + 4);
Expand All @@ -63,10 +63,10 @@ protected function checkMethodCalls(File $phpcsFile, $stackPtr) {
/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
*
*
* @return void
*/
protected function checkConditions($phpcsFile, $stackPtr) {
protected function checkConditions(File $phpcsFile, int $stackPtr): void {
$tokens = $phpcsFile->getTokens();

$openingBraceIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
Expand Down Expand Up @@ -99,7 +99,7 @@ protected function checkConditions($phpcsFile, $stackPtr) {
*
* @return bool
*/
protected function isFixableInlineAssignment(File $phpcsFile, $startIndex, $endIndex, &$indexEqualSign) {
protected function isFixableInlineAssignment(File $phpcsFile, int $startIndex, int $endIndex, int &$indexEqualSign): bool {
$tokens = $phpcsFile->getTokens();

$hasInlineAssignment = false;
Expand Down
24 changes: 12 additions & 12 deletions PSR2R/Sniffs/ControlStructures/TernarySpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public function process(File $phpcsFile, $stackPtr) {
/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
*
*
* @return void
*/
protected function assertSpaceBefore(File $phpcsFile, $stackPtr) {
protected function assertSpaceBefore(File $phpcsFile, int $stackPtr): void {
$previous = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
if ($stackPtr - $previous > 1) {
$this->assertSingleSpaceBeforeIfNotMultiline($phpcsFile, $stackPtr, $previous);
Expand All @@ -58,10 +58,10 @@ protected function assertSpaceBefore(File $phpcsFile, $stackPtr) {
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
* @param int $previous
*
*
* @return void
*/
protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, $stackPtr, $previous) {
protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, int $stackPtr, int $previous): void {
$tokens = $phpcsFile->getTokens();

if ($tokens[$stackPtr]['line'] !== $tokens[$previous]['line']) {
Expand All @@ -81,10 +81,10 @@ protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, $stack
/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $thenIndex
*
*
* @return void
*/
protected function checkAfter(File $phpcsFile, $thenIndex) {
protected function checkAfter(File $phpcsFile, int $thenIndex): void {
$elseIndex = $phpcsFile->findNext(T_INLINE_ELSE, $thenIndex + 1);
if (!$elseIndex) {
return;
Expand All @@ -106,10 +106,10 @@ protected function checkAfter(File $phpcsFile, $thenIndex) {
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $thenIndex
* @param int $elseIndex
*
*
* @return void
*/
protected function assertNoSpaceBetween(File $phpcsFile, $thenIndex, $elseIndex) {
protected function assertNoSpaceBetween(File $phpcsFile, int $thenIndex, int $elseIndex): void {
if ($elseIndex - $thenIndex === 1) {
return;
}
Expand All @@ -128,10 +128,10 @@ protected function assertNoSpaceBetween(File $phpcsFile, $thenIndex, $elseIndex)
/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
*
*
* @return void
*/
protected function assertSpaceAfter(File $phpcsFile, $stackPtr) {
protected function assertSpaceAfter(File $phpcsFile, int $stackPtr): void {
$nextIndex = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
if ($nextIndex - $stackPtr > 1) {
$this->assertSingleSpaceAfterIfNotMultiline($phpcsFile, $stackPtr, $nextIndex);
Expand All @@ -152,10 +152,10 @@ protected function assertSpaceAfter(File $phpcsFile, $stackPtr) {
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
* @param int $next
*
*
* @return void
*/
protected function assertSingleSpaceAfterIfNotMultiline(File $phpcsFile, $stackPtr, $next) {
protected function assertSingleSpaceAfterIfNotMultiline(File $phpcsFile, int $stackPtr, int $next): void {
$tokens = $phpcsFile->getTokens();

if ($tokens[$stackPtr]['line'] !== $tokens[$next]['line']) {
Expand Down
6 changes: 3 additions & 3 deletions PSR2R/Sniffs/ControlStructures/UnneededElseSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ public function process(File $phpcsFile, $stackPtr) {
/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
*
*
* @return bool
*/
protected function isNotLastCondition(File $phpcsFile, $stackPtr) {
protected function isNotLastCondition(File $phpcsFile, int $stackPtr): bool {
$tokens = $phpcsFile->getTokens();

// Abort if not known
Expand All @@ -160,7 +160,7 @@ protected function isNotLastCondition(File $phpcsFile, $stackPtr) {
*
* @return void
*/
protected function fixElseIfToIf(File $phpcsFile, $stackPtr) {
protected function fixElseIfToIf(File $phpcsFile, int $stackPtr): void {
$tokens = $phpcsFile->getTokens();

$phpcsFile->fixer->beginChangeset();
Expand Down
9 changes: 3 additions & 6 deletions PSR2R/Sniffs/Methods/MethodDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,15 @@ public function __construct() {
}

/**
* @param \PHP_CodeSniffer\Files\File $phpcsFile
* @param int $stackPtr
*
* @return void
* @inheritDoc
*/
protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) {
protected function processTokenOutsideScope(File $phpcsFile, $stackPtr): void {
// Nothing to do here.
}

/**
* @inheritDoc
*
*
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException
*/
protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) {
Expand Down
Loading

0 comments on commit bf42618

Please sign in to comment.