Skip to content

Commit

Permalink
Merge pull request #1710 from PHPCompatibility/feature/various-minor-…
Browse files Browse the repository at this point in the history
…cs-tweaks

Various minor cs tweaks
  • Loading branch information
wimg committed Jun 7, 2024
2 parents 96072c3 + 5b6b511 commit c2858c4
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions PHPCompatibility/Sniffs/Classes/NewClassesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1431,13 +1431,13 @@ private function processUseToken(File $phpcsFile, $stackPtr)
$splitUseStatement = UseStatements::splitImportUseStatement($phpcsFile, $stackPtr);

foreach ($splitUseStatement['name'] as $name => $fullyQualifiedName) {
$lowerFullyQualifiedName = strtolower($fullyQualifiedName);
$lowerFullyQualifiedName = \strtolower($fullyQualifiedName);

if (isset($this->newClasses[$lowerFullyQualifiedName])) {
continue;
}

$this->importedClasses[strtolower($name)] = true;
$this->importedClasses[\strtolower($name)] = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace PHPCompatibility\Sniffs\Classes;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHPCompatibility\Helpers\ScannedCode;
use PHPCompatibility\Sniff;
use PHPCSUtils\Utils\FunctionDeclarations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPCompatibility\Helpers\ScannedCode;
use PHPCompatibility\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHPCSUtils\Utils\FunctionDeclarations;
use PHPCSUtils\Utils\Scopes;
use PHPCSUtils\Utils\Variables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NonStaticMagicMethodsSniff extends Sniff
'static' => false,
],
'__destruct' => [
'static' => false,
'static' => false,
],
'__clone' => [
'static' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PHPCompatibility\Helpers\ScannedCode;
use PHPCompatibility\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\Tokens\Collections;
use PHPCSUtils\Utils\Conditions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ private function processUseToken(File $phpcsFile, $stackPtr)
$splitUseStatement = UseStatements::splitImportUseStatement($phpcsFile, $stackPtr);

foreach ($splitUseStatement['name'] as $name => $fullyQualifiedName) {
$lowerFullyQualifiedName = strtolower($fullyQualifiedName);
$lowerFullyQualifiedName = \strtolower($fullyQualifiedName);

// If the imported declaration is imported from the internal namespace it will not be excluded.
if (isset($this->internalInterfaces[$lowerFullyQualifiedName])) {
continue;
}

$this->importedDeclarations[strtolower($name)] = true;
$this->importedDeclarations[\strtolower($name)] = true;
}
}
}
4 changes: 2 additions & 2 deletions PHPCompatibility/Sniffs/Interfaces/NewInterfacesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,14 @@ private function processUseToken(File $phpcsFile, $stackPtr)
$splitUseStatement = UseStatements::splitImportUseStatement($phpcsFile, $stackPtr);

foreach ($splitUseStatement['name'] as $name => $fullyQualifiedName) {
$lowerFullyQualifiedName = strtolower($fullyQualifiedName);
$lowerFullyQualifiedName = \strtolower($fullyQualifiedName);

// If the imported declaration is imported from the internal namespace it will not be excluded.
if (isset($this->newInterfaces[$lowerFullyQualifiedName])) {
continue;
}

$this->importedDeclaration[strtolower($name)] = true;
$this->importedDeclaration[\strtolower($name)] = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function processParameters(File $phpcsFile, $stackPtr, $functionName, $pa
return;
}

$secondParamContent = ltrim($secondParam['clean'], ' \\'); // Trim off potential leading namespace separator for FQN.
$secondParamContent = \ltrim($secondParam['clean'], ' \\'); // Trim off potential leading namespace separator for FQN.
if ($secondParamContent !== 'HASH_HMAC'
&& $secondParamContent !== (string) \HASH_HMAC
) {
Expand Down
11 changes: 7 additions & 4 deletions PHPCompatibility/Tests/BaseSniffTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
namespace PHPCompatibility\Tests;

use PHPUnit\Framework\TestCase;
use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Files\LocalFile;
use PHP_CodeSniffer\Ruleset;
use PHPCSUtils\BackCompat\Helper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;

Expand Down Expand Up @@ -48,7 +51,7 @@ abstract class BaseSniffTestCase extends TestCase
*
* @since 7.0.4
*
* @var array<string, array<string, File>>
* @var array<string, array<string, \PHP_CodeSniffer\Files\File>>
*/
public static $sniffFiles = [];

Expand Down Expand Up @@ -145,17 +148,17 @@ public function sniffFile($pathToFile, $targetPhpVersion = 'none')
if (isset(self::$sniffFiles[$pathToFile]['only_parsed']) === false) {
try {
// PHPCS 3.x, 4.x.
$config = new \PHP_CodeSniffer\Config();
$config = new Config();
$config->cache = false;
$config->standards = [self::STANDARD_NAME];
$config->sniffs = [$this->getSniffCode()];
$config->ignored = [];

self::$lastConfig = $config;

$ruleset = new \PHP_CodeSniffer\Ruleset($config);
$ruleset = new Ruleset($config);

self::$sniffFiles[$pathToFile]['only_parsed'] = new \PHP_CodeSniffer\Files\LocalFile($pathToFile, $ruleset, $config);
self::$sniffFiles[$pathToFile]['only_parsed'] = new LocalFile($pathToFile, $ruleset, $config);
self::$sniffFiles[$pathToFile]['only_parsed']->parse();
} catch (\Exception $e) {
$this->fail('An unexpected exception has been caught when parsing file "' . $pathToFile . '" : ' . $e->getMessage());
Expand Down
5 changes: 3 additions & 2 deletions PHPCompatibility/Tests/Classes/NewClassesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCompatibility\Tests\Classes;

use PHP_CodeSniffer\Files\LocalFile;
use PHPCompatibility\Tests\BaseSniffTestCase;

/**
Expand Down Expand Up @@ -346,8 +347,8 @@ public function testNoViolationsInFileIfOtherNamespace()
$sharedRuleSet = $file->ruleset;
$sharedConfig = $file->config;

$forgedLocalFile = new \PHP_CodeSniffer\Files\LocalFile(
realpath(__DIR__ . '/NewClassesUsesNoLeakUnitTest.inc'),
$forgedLocalFile = new LocalFile(
\realpath(__DIR__ . '/NewClassesUsesNoLeakUnitTest.inc'),
$sharedRuleSet,
$sharedConfig
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCompatibility\Tests\Interfaces;

use PHP_CodeSniffer\Files\LocalFile;
use PHPCompatibility\Tests\BaseSniffTestCase;

/**
Expand Down Expand Up @@ -175,8 +176,8 @@ public function testNoViolationsInFileIfOtherNamespace()
$sharedRuleSet = $file->ruleset;
$sharedConfig = $file->config;

$forgedLocalFile = new \PHP_CodeSniffer\Files\LocalFile(
realpath(__DIR__ . '/InternalInterfacesUnitTest.inc'),
$forgedLocalFile = new LocalFile(
\realpath(__DIR__ . '/InternalInterfacesUnitTest.inc'),
$sharedRuleSet,
$sharedConfig
);
Expand Down
5 changes: 3 additions & 2 deletions PHPCompatibility/Tests/Interfaces/NewInterfacesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCompatibility\Tests\Interfaces;

use PHP_CodeSniffer\Files\LocalFile;
use PHPCompatibility\Tests\BaseSniffTestCase;

/**
Expand Down Expand Up @@ -239,8 +240,8 @@ public function testNoViolationsInFileIfOtherNamespace()
$sharedRuleSet = $file->ruleset;
$sharedConfig = $file->config;

$forgedLocalFile = new \PHP_CodeSniffer\Files\LocalFile(
realpath(__DIR__ . '/NewInterfacesUnitTest.inc'),
$forgedLocalFile = new LocalFile(
\realpath(__DIR__ . '/NewInterfacesUnitTest.inc'),
$sharedRuleSet,
$sharedConfig
);
Expand Down

0 comments on commit c2858c4

Please sign in to comment.