From 03f321c86525970d4a6225240d094aa204e155bd Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 6 Apr 2017 12:35:44 +0200 Subject: [PATCH] FEATURE: Add tests and fix issues * Add test for IsACallSniff. * Fix doublicate finds in IsACallSniff and InstantiationWithObjectManagerSniff. * Both didn't stop looking for class at end of expression. Relates: #46 --- .../InstantiationWithObjectManagerSniff.php | 6 +++- .../Sniffs/LegacyClassnames/IsACallSniff.php | 6 +++- .../Expected.json | 24 ++------------ .../IsACallSniff/Expected.diff | 14 ++++++++ .../IsACallSniff/Expected.json | 33 +++++++++++++++++++ .../IsACallSniff/InputFileForIssues.php | 31 +++++++++++++++++ 6 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.diff create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.json create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/InputFileForIssues.php diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php index 0afe79c..aa1d055 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php @@ -61,7 +61,11 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff ex return; } - $classnamePosition = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr); + $classnamePosition = $phpcsFile->findNext( + T_CONSTANT_ENCAPSED_STRING, + $stackPtr, + $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr) + ); if ($classnamePosition === false) { return; } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php index 3848adf..62e90a9 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php @@ -59,7 +59,11 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassname return; } - $classnamePosition = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $phpcsFile->findNext(T_COMMA, $stackPtr)); + $classnamePosition = $phpcsFile->findNext( + T_CONSTANT_ENCAPSED_STRING, + $phpcsFile->findNext(T_COMMA, $stackPtr), + $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr) + ); if ($classnamePosition === false) { return; } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff/Expected.json index d2a52d1..2ebb599 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff/Expected.json @@ -1,7 +1,7 @@ { "files": { "InputFileForIssues.php": { - "errors": 6, + "errors": 4, "messages": [ { "column": 27, @@ -12,15 +12,6 @@ "source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname", "type": "ERROR" }, - { - "column": 27, - "fixable": true, - "line": 24, - "message": "Legacy classes are not allowed; found \"Tx_Extbase_Command_HelpCommandController\", use \"TYPO3\\CMS\\Extbase\\Command\\HelpCommandController\" instead", - "severity": 5, - "source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname", - "type": "ERROR" - }, { "column": 27, "fixable": true, @@ -39,15 +30,6 @@ "source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname", "type": "ERROR" }, - { - "column": 11, - "fixable": true, - "line": 31, - "message": "Legacy classes are not allowed; found \"Tx_Extbase_Command_HelpCommandController\", use \"TYPO3\\CMS\\Extbase\\Command\\HelpCommandController\" instead", - "severity": 5, - "source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname", - "type": "ERROR" - }, { "column": 11, "fixable": true, @@ -62,8 +44,8 @@ } }, "totals": { - "errors": 6, - "fixable": 6, + "errors": 4, + "fixable": 4, "warnings": 0 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.diff new file mode 100644 index 0000000..64f197e --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.diff @@ -0,0 +1,14 @@ +--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/InputFileForIssues.php ++++ PHP_CodeSniffer +@@ -23,9 +23,9 @@ + if (is_a($a, t3lib_Singleton::class)) { + // do something + } +-if (is_a($a, 't3lib_Singleton')) { ++if (is_a($a, '\TYPO3\CMS\Core\SingletonInterface')) { + // do something + } +-if (is_a($a, '\t3lib_Singleton')) { ++if (is_a($a, '\TYPO3\CMS\Core\SingletonInterface')) { + // do something + } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.json new file mode 100644 index 0000000..d754658 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/Expected.json @@ -0,0 +1,33 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 2, + "messages": [ + { + "column": 14, + "fixable": true, + "line": 26, + "message": "Legacy classes are not allowed; found \"t3lib_Singleton\", use \"TYPO3\\CMS\\Core\\SingletonInterface\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.IsACall.legacyClassname", + "type": "ERROR" + }, + { + "column": 14, + "fixable": true, + "line": 29, + "message": "Legacy classes are not allowed; found \"t3lib_Singleton\", use \"TYPO3\\CMS\\Core\\SingletonInterface\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.IsACall.legacyClassname", + "type": "ERROR" + } + ], + "warnings": 0 + } + }, + "totals": { + "errors": 2, + "fixable": 2, + "warnings": 0 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/InputFileForIssues.php new file mode 100644 index 0000000..4265076 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff/InputFileForIssues.php @@ -0,0 +1,31 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +// Handled by static call sniff. +if (is_a($a, t3lib_Singleton::class)) { + // do something +} +if (is_a($a, 't3lib_Singleton')) { + // do something +} +if (is_a($a, '\t3lib_Singleton')) { + // do something +}