From e9ce7c5bd0011cf29ef7267df0b08be5208e4965 Mon Sep 17 00:00:00 2001
From: Asis Pattisahusiwa <79239132+asispts@users.noreply.github.com>
Date: Fri, 3 Nov 2023 17:14:59 +0700
Subject: [PATCH] Remove useless property, parameter, and return annotations
(#16)
* Detect useless property annotation
* Detect useless return annotation
* Detect useless parameter annotation
---
ptscs/Sniffs/PSR12/FileHeaderSniff.php | 18 +++----
ptscs/ruleset.xml | 5 ++
.../TypeHints/ParameterTypeHintTest.php | 25 +++++++++
.../TypeHints/PropertyTypeHintTest.php | 25 +++++++++
.../Slevomat/TypeHints/ReturnTypeHintTest.php | 23 +++++++++
.../TypeHints/UselessDocblockTest.php | 26 ++++++++++
.../_data/ParameterTypeHint.php.fixed | 12 +++++
.../TypeHints/_data/ParameterTypeHint.php.inc | 13 +++++
.../_data/PropertyTypeHint.php.fixed | 48 +++++++++++++++++
.../TypeHints/_data/PropertyTypeHint.php.inc | 51 +++++++++++++++++++
.../TypeHints/_data/ReturnTypeHint.php.fixed | 18 +++++++
.../TypeHints/_data/ReturnTypeHint.php.inc | 19 +++++++
.../TypeHints/_data/UselessDocblock.php.fixed | 26 ++++++++++
.../TypeHints/_data/UselessDocblock.php.inc | 28 ++++++++++
14 files changed, 326 insertions(+), 11 deletions(-)
create mode 100644 tests/Sniffs/Slevomat/TypeHints/ParameterTypeHintTest.php
create mode 100644 tests/Sniffs/Slevomat/TypeHints/PropertyTypeHintTest.php
create mode 100644 tests/Sniffs/Slevomat/TypeHints/ReturnTypeHintTest.php
create mode 100644 tests/Sniffs/Slevomat/TypeHints/UselessDocblockTest.php
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/ParameterTypeHint.php.fixed
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/ParameterTypeHint.php.inc
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/PropertyTypeHint.php.fixed
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/PropertyTypeHint.php.inc
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/ReturnTypeHint.php.fixed
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/ReturnTypeHint.php.inc
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/UselessDocblock.php.fixed
create mode 100644 tests/Sniffs/Slevomat/TypeHints/_data/UselessDocblock.php.inc
diff --git a/ptscs/Sniffs/PSR12/FileHeaderSniff.php b/ptscs/Sniffs/PSR12/FileHeaderSniff.php
index 990d351..bdfea02 100644
--- a/ptscs/Sniffs/PSR12/FileHeaderSniff.php
+++ b/ptscs/Sniffs/PSR12/FileHeaderSniff.php
@@ -19,9 +19,9 @@ final class FileHeaderSniff implements Sniff
/**
* Returns an array of tokens this test wants to listen for.
*
- * @return array
+ * @return int[]
*/
- public function register()
+ public function register(): array
{
return [\T_OPEN_TAG];
}
@@ -33,9 +33,8 @@ public function register()
* @param int $stackPtr The position of the current
* token in the stack.
*
- * @return int|null
*/
- public function process(File $phpcsFile, $stackPtr)
+ public function process(File $phpcsFile, $stackPtr): ?int
{
$tokens = $phpcsFile->getTokens();
@@ -49,7 +48,7 @@ public function process(File $phpcsFile, $stackPtr)
$headerLines = $this->getHeaderLines($phpcsFile, $openTag);
if (empty($headerLines) === true && $openTag === $stackPtr) {
// No content in the file.
- return;
+ return null;
}
$possibleHeaders[$openTag] = $headerLines;
@@ -123,7 +122,7 @@ public function process(File $phpcsFile, $stackPtr)
*
* @return array
*/
- public function getHeaderLines(File $phpcsFile, $stackPtr)
+ public function getHeaderLines(File $phpcsFile, $stackPtr): array
{
$tokens = $phpcsFile->getTokens();
@@ -276,12 +275,9 @@ public function getHeaderLines(File $phpcsFile, $stackPtr)
* Check the spacing and grouping of the statements inside each header block.
*
* @param File $phpcsFile The file being scanned.
- * @param array $headerLines Header information, as sourced
- * from getHeaderLines().
- *
- * @return int|null
+ * @param array $headerLines Header information, as sourced from getHeaderLines().
*/
- public function processHeaderLines(File $phpcsFile, $headerLines)
+ public function processHeaderLines(File $phpcsFile, $headerLines): void
{
$tokens = $phpcsFile->getTokens();
diff --git a/ptscs/ruleset.xml b/ptscs/ruleset.xml
index 5c226fc..84f0e62 100644
--- a/ptscs/ruleset.xml
+++ b/ptscs/ruleset.xml
@@ -194,6 +194,11 @@
+
+
+
+
+