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

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: 8 additions & 3 deletions PHPCSUtils/BackCompat/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ public static function getTabWidth(File $phpcsFile)
* command-line or the ruleset.
*
* @since 1.0.0
* @since 1.0.10 The `File` type declaration has been removed from the parameter declaration.
*
* @param \PHP_CodeSniffer\Files\File|null $phpcsFile Optional. The current file being processed.
*
* @return string Encoding. Defaults to the PHPCS native default, which is 'utf-8'
* for PHPCS 3.x.
*/
public static function getEncoding(File $phpcsFile = null)
public static function getEncoding($phpcsFile = null)
{
$default = 'utf-8';

Expand All @@ -176,14 +177,18 @@ public static function getEncoding(File $phpcsFile = null)
* Check whether the "--ignore-annotations" option is in effect.
*
* @since 1.0.0
* @since 1.0.10 The `File` type declaration has been removed from the parameter declaration.
*
* @param \PHP_CodeSniffer\Files\File|null $phpcsFile Optional. The current file being processed.
*
* @return bool `TRUE` if annotations should be ignored, `FALSE` otherwise.
*/
public static function ignoreAnnotations(File $phpcsFile = null)
public static function ignoreAnnotations($phpcsFile = null)
{
if (isset($phpcsFile, $phpcsFile->config->annotations)) {
if (isset($phpcsFile)
&& $phpcsFile instanceof File
&& isset($phpcsFile->config->annotations)
) {
return ! $phpcsFile->config->annotations;
}

Expand Down
25 changes: 25 additions & 0 deletions Tests/BackCompat/Helper/GetCommandLineDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use PHPCSUtils\BackCompat\Helper;
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
use stdClass;

/**
* Test class.
Expand Down Expand Up @@ -200,4 +201,28 @@ public function testIgnoreAnnotationsSetViaProperty()

$this->assertTrue($result);
}

/**
* Test the ignoreAnnotations() method.
*
* @covers ::ignoreAnnotations
*
* @return void
*/
public function testIgnoreAnnotationsUsesGetConfigDataWhenInvalidFileParamPassed()
{
$config = null;
if (isset(self::$phpcsFile->config) === true) {
$config = self::$phpcsFile->config;
}

Helper::setConfigData('annotations', false, true, $config);

$result = Helper::ignoreAnnotations(new stdClass());

// Restore defaults before moving to the next test.
Helper::setConfigData('annotations', true, true, $config);

$this->assertTrue($result);
}
}
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ parameters:
-
message: '`^Parameter #[0-9]+ \$\S+ of static method PHPCSUtils\\(?!Tests)[A-Za-z]+\\[A-Za-z]+::[A-Za-z]+\(\) expects [^,]+, \S+ given\.$`'
paths:
- Tests/BackCompat/Helper/GetCommandLineDataTest.php
- Tests/BackCompat/BCFile/GetTokensAsStringTest.php
- Tests/Exceptions/TestTargetNotFound/TestTargetNotFoundTest.php
- Tests/Fixers/SpacesFixer/SpacesFixerExceptionsTest.php
Expand Down