Skip to content
Prev Previous commit
Next Next commit
AC-1549: Made suggestions
  • Loading branch information
svera committed Oct 26, 2021
commit 852a479d8a4ba28fe21d718672dee5934119ec2b
22 changes: 12 additions & 10 deletions Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ class ObsoleteConnectionSniff implements Sniff
* @var string[]
*/
private $obsoleteMethods = [
'_getReadConnection' => 'FoundObsoleteMethod_getReadConnection',
'_getWriteConnection' => 'FoundObsoleteMethod_getWriteConnection',
'_getReadAdapter' => 'FoundObsoleteMethod_getReadAdapter',
'_getWriteAdapter' => 'FoundObsoleteMethod_getWriteAdapter',
'getReadConnection' => 'FoundObsoleteMethodGetReadConnection',
'getWriteConnection' => 'FoundObsoleteMethodGetWriteConnection',
'getReadAdapter' => 'FoundObsoleteMethodGetReadAdapter',
'getWriteAdapter' => 'FoundObsoleteMethodGetWriteAdapter',
'_getReadConnection',
'_getWriteConnection',
'_getReadAdapter',
'_getWriteAdapter',
'getReadConnection',
'getWriteConnection',
'getReadAdapter',
'getWriteAdapter',
];

private const OBSOLETE_METHOD_ERROR_CODE = 'ObsoleteMethodFound';

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -56,12 +58,12 @@ private function validateObsoleteMethod(File $phpcsFile, int $stackPtr)
$tokens = $phpcsFile->getTokens();
$stringPos = $phpcsFile->findNext(T_STRING, $stackPtr + 1);

foreach ($this->obsoleteMethods as $method => $errorCode) {
foreach ($this->obsoleteMethods as $method) {
if ($tokens[$stringPos]['content'] === $method) {
$phpcsFile->addWarning(
sprintf("Contains obsolete method: %s. Please use getConnection method instead.", $method),
$stackPtr,
$errorCode
self::OBSOLETE_METHOD_ERROR_CODE
);
}
}
Expand Down