Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues found by Psalm #2084

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
10 changes: 3 additions & 7 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Config
/**
* Command line values that the user has supplied directly.
*
* @var array<string, TRUE>
* @var array<string, bool|array>
*/
private static $overriddenDefaults = [];

Expand Down Expand Up @@ -745,9 +745,7 @@ public function processLongArgument($arg, $pos)
self::$overriddenDefaults['annotations'] = true;
break;
case 'config-set':
if (isset($this->cliArgs[($pos + 1)]) === false
|| isset($this->cliArgs[($pos + 2)]) === false
) {
if (isset($this->cliArgs[($pos + 1)], $this->cliArgs[($pos + 2)]) === false) {
$error = 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL;
$error .= $this->printShortUsage(true);
throw new DeepExitException($error, 3);
Expand Down Expand Up @@ -803,9 +801,7 @@ public function processLongArgument($arg, $pos)
ob_end_clean();
throw new DeepExitException($output, 0);
case 'runtime-set':
if (isset($this->cliArgs[($pos + 1)]) === false
|| isset($this->cliArgs[($pos + 2)]) === false
) {
if (isset($this->cliArgs[($pos + 1)], $this->cliArgs[($pos + 2)]) === false) {
$error = 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL;
$error .= $this->printShortUsage(true);
throw new DeepExitException($error, 3);
Expand Down
34 changes: 11 additions & 23 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,13 @@ public function addError(
/**
* Records a warning against a specific token in the file.
*
* @param string $warning The error message.
* @param int $stackPtr The stack position where the error occurred.
* @param string $code A violation code unique to the sniff message.
* @param array $data Replacements for the warning message.
* @param int $severity The severity level for this warning. A value of 0
* will be converted into the default severity level.
* @param boolean $fixable Can the warning be fixed by the sniff?
* @param string $warning The error message.
* @param int|null $stackPtr The stack position where the error occurred.
* @param string $code A violation code unique to the sniff message.
* @param array $data Replacements for the warning message.
* @param int $severity The severity level for this warning. A value of 0
* will be converted into the default severity level.
* @param boolean $fixable Can the warning be fixed by the sniff?
*
* @return boolean
*/
Expand Down Expand Up @@ -1108,18 +1108,6 @@ public function getWarningCount()
}//end getWarningCount()


/**
* Returns the number of successes recorded.
*
* @return int
*/
public function getSuccessCount()
{
return $this->successCount;

}//end getSuccessCount()


/**
* Returns the number of fixable errors/warnings raised.
*
Expand Down Expand Up @@ -1902,10 +1890,10 @@ public function isReference($stackPtr)
* Returns the content of the tokens from the specified start position in
* the token stack for the specified length.
*
* @param int $start The position to start from in the token stack.
* @param int $length The length of tokens to traverse from the start pos.
* @param int $origContent Whether the original content or the tab replaced
* content should be used.
* @param int $start The position to start from in the token stack.
* @param int $length The length of tokens to traverse from the start pos.
* @param int|false $origContent Whether the original content or the tab replaced
* content should be used.
*
* @return string The token contents.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Files/FileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function current()
/**
* Return the file path of the current file being processed.
*
* @return void
* @return string
*/
public function key()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Fixer
* else. This is the array that is updated as fixes are made, not the file's
* token array. Imploding this array will give you the file content back.
*
* @var array<int, string>
* @var array<int, string|int>
*/
private $tokens = [];

Expand All @@ -60,7 +60,7 @@ class Fixer
* We don't allow the same token to be fixed more than once each time
* through a file as this can easily cause conflicts between sniffs.
*
* @var int[]
* @var array<int, string|int>
*/
private $fixedTokens = [];

Expand All @@ -70,7 +70,7 @@ class Fixer
* If a token is being "fixed" back to its last value, the fix is
* probably conflicting with another.
*
* @var array<int, string>
* @var array<int, array<string, string|int>>
*/
private $oldTokenValues = [];

Expand Down
8 changes: 4 additions & 4 deletions src/Generators/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public function __construct(Ruleset $ruleset)
/**
* Retrieves the title of the sniff from the DOMNode supplied.
*
* @param \DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
* standard file.
* @param \DOMElement $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
* standard file.
*
* @return string
*/
protected function getTitle(\DOMNode $doc)
protected function getTitle(\DOMElement $doc)
{
return $doc->getAttribute('title');

Expand Down
4 changes: 2 additions & 2 deletions src/Generators/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ protected function printTextBlock(\DOMNode $node)
/**
* Print a code comparison block found in a standard.
*
* @param \DOMNode $node The DOMNode object for the code comparison block.
* @param \DOMElement $node The DOMNode object for the code comparison block.
*
* @return void
*/
protected function printCodeComparisonBlock(\DOMNode $node)
protected function printCodeComparisonBlock(\DOMElement $node)
{
$codeBlocks = $node->getElementsByTagName('code');

Expand Down
4 changes: 2 additions & 2 deletions src/Generators/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ protected function printTextBlock(\DOMNode $node)
/**
* Print a code comparison block found in a standard.
*
* @param \DOMNode $node The DOMNode object for the code comparison block.
* @param \DOMElement $node The DOMNode object for the code comparison block.
*
* @return void
*/
protected function printCodeComparisonBlock(\DOMNode $node)
protected function printCodeComparisonBlock(\DOMElement $node)
{
$codeBlocks = $node->getElementsByTagName('code');

Expand Down
4 changes: 2 additions & 2 deletions src/Generators/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ protected function printTextBlock(\DOMNode $node)
/**
* Print a code comparison block found in a standard.
*
* @param \DOMNode $node The DOMNode object for the code comparison block.
* @param \DOMElement $node The DOMNode object for the code comparison block.
*
* @return void
*/
protected function printCodeComparisonBlock(\DOMNode $node)
protected function printCodeComparisonBlock(\DOMElement $node)
{
$codeBlocks = $node->getElementsByTagName('code');
$first = trim($codeBlocks->item(0)->nodeValue);
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Cbf.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Cbf implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Checkstyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Checkstyle implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Code implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Csv implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Diff implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Emacs.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Emacs implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Full.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Full implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Info implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Json implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Junit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Junit implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Notifysend.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public function __construct()
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ interface Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Source implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Reports/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Summary implements Report
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
* @param array $report Prepared report data.
* @param File $phpcsFile The file being reported on.
* @param bool $showSources Show sources?
* @param int $width Maximum allowed line width.
*
* @return bool
*/
Expand Down
Loading