diff --git a/Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php b/Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php new file mode 100644 index 00000000..a1425cab --- /dev/null +++ b/Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php @@ -0,0 +1,71 @@ +validateObsoleteMethod($phpcsFile, $stackPtr); + } + + /** + * Check if obsolete methods are used + * + * @param File $phpcsFile + * @param int $stackPtr + */ + private function validateObsoleteMethod(File $phpcsFile, int $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $stringPos = $phpcsFile->findNext(T_STRING, $stackPtr + 1); + + foreach ($this->obsoleteMethods as $method) { + if ($tokens[$stringPos]['content'] === $method) { + $phpcsFile->addWarning( + sprintf("Contains obsolete method: %s. Please use getConnection method instead.", $method), + $stackPtr, + self::ERROR_CODE_METHOD + ); + } + } + } +} diff --git a/Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.inc b/Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.inc new file mode 100644 index 00000000..70c71642 --- /dev/null +++ b/Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.inc @@ -0,0 +1,36 @@ +_getReadConnection(); + +$connection = new Connection(); +return $connection->_getWriteConnection(); + +$this->getMethod( + function($param){ + $param->_getWriteAdapter(); + } +); + +$writeAdapter = $this->getWriteAdapter(); + +protected function getConnection() +{ + return $this->_resource->getReadConnection($this->connection); +} + +return $this->_getReadAdapter(); + +$this->getReadAdapterMyMehtod(); + +private function getReadAdapter() +{ + +} + +$getWriteAdapter = new WriteAdapter(); + +$getWriteAdapter = $this->getWriteAdapter(); diff --git a/Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.php b/Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.php new file mode 100644 index 00000000..a451d2cf --- /dev/null +++ b/Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.php @@ -0,0 +1,36 @@ + 1, + 10 => 1, + 14 => 1, + 18 => 1, + 22 => 1, + 25 => 1, + 29 => 1, + 36 => 1 + ]; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 1b1c7f1b..c9d22463 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -313,6 +313,10 @@ 8 warning + + 8 + warning +