diff --git a/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php new file mode 100644 index 00000000..70fcfabe --- /dev/null +++ b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php @@ -0,0 +1,79 @@ +getTokens(); + + foreach ($this->functions as $function) { + if (strpos($tokens[$stackPtr]['content'], $function) !== 0) { + continue; + } + $tryPosition = $phpcsFile->findPrevious(T_TRY, $stackPtr - 1); + + if ($tryPosition !== false) { + $tryTag = $tokens[$tryPosition]; + $start = $tryTag['scope_opener']; + $end = $tryTag['scope_closer']; + if ($stackPtr > $start && $stackPtr < $end) { + // element is warped by try no check required + return; + } + } + + $phpcsFile->addWarning( + $this->warningMessage, + $stackPtr, + $this->warningCode + ); + } + } +} diff --git a/Magento2/Tests/Exceptions/TryProcessSystemResourcesUnitTest.inc b/Magento2/Tests/Exceptions/TryProcessSystemResourcesUnitTest.inc new file mode 100644 index 00000000..66f23840 --- /dev/null +++ b/Magento2/Tests/Exceptions/TryProcessSystemResourcesUnitTest.inc @@ -0,0 +1,29 @@ + 1, + 24 => 1, + 26 => 1, + 28 => 1 + ]; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 8898695b..df66ac69 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -153,6 +153,14 @@ 8 warning + + 8 + warning + */_files/* + */Fixtures/* + */Test/* + *Test.php + 8 warning