Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Fix error
  • Loading branch information
rmsundar1 committed Dec 10, 2021
commit 38c79974dc36bfe5c4865a74d5ca381c54bec8d2
37 changes: 11 additions & 26 deletions Magento2/Sniffs/Exceptions/DirectThrowSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,19 @@ public function process(File $phpcsFile, $stackPtr)
$exceptionString = 'Exception';
$customExceptionFound = false;
foreach ($tokens as $key => $token) {
if ($token['code'] !== T_USE) {
if ($token['code'] !== T_USE) {
continue;
}
$endOfUse = $phpcsFile->findEndOfStatement($key);
$useStatementValue = $this->getFullClassNameAndAlias($tokens, $key, $endOfUse);
// we safely consider use statement has alias will not be a direct exception class
if (!empty($useStatementValue['alias'])) {
continue;
}
if (substr($useStatementValue['name'], 0, strlen($exceptionString)) !== $exceptionString
&& substr($useStatementValue['name'], -strlen($exceptionString)) === $exceptionString
&& $useStatementValue['name'] !== $exceptionString
}
$endOfUse = $phpcsFile->findEndOfStatement($key);
$useStatementValue = $this->getFullClassNameAndAlias($tokens, $key, $endOfUse);
//we safely consider use statement has alias will not be a direct exception class
if (empty($useStatementValue['alias'])) {
if (substr($useStatementValue['name'], 0, strlen($exceptionString)) !== $exceptionString
&& substr($useStatementValue['name'], -strlen($exceptionString)) === $exceptionString
&& $useStatementValue['name'] !== $exceptionString
) {
$customExceptionFound = true;
break;
}
}
$endOfUse = $phpcsFile->findEndOfStatement($key);
$useStatementValue = $this->getFullClassNameAndAlias($tokens, $key, $endOfUse);
//we safely consider use statement has alias will not be a direct exception class
if (empty($useStatementValue['alias'])) {
if (substr($useStatementValue['name'], 0, strlen($exceptionString)) !== $exceptionString
&& substr($useStatementValue['name'], -strlen($exceptionString)) === $exceptionString
&& $useStatementValue['name'] !== $exceptionString
) {
$customExceptionFound = true;
break;
}
$customExceptionFound = true;
break;
}
}
}
Expand Down