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
This commit is contained in:
parent
af74a5db21
commit
03f321c865
6 changed files with 91 additions and 23 deletions
|
@ -61,7 +61,11 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff ex
|
||||||
return;
|
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) {
|
if ($classnamePosition === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,11 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassname
|
||||||
return;
|
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) {
|
if ($classnamePosition === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"files": {
|
"files": {
|
||||||
"InputFileForIssues.php": {
|
"InputFileForIssues.php": {
|
||||||
"errors": 6,
|
"errors": 4,
|
||||||
"messages": [
|
"messages": [
|
||||||
{
|
{
|
||||||
"column": 27,
|
"column": 27,
|
||||||
|
@ -12,15 +12,6 @@
|
||||||
"source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname",
|
"source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname",
|
||||||
"type": "ERROR"
|
"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,
|
"column": 27,
|
||||||
"fixable": true,
|
"fixable": true,
|
||||||
|
@ -39,15 +30,6 @@
|
||||||
"source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname",
|
"source": "Typo3Update.LegacyClassnames.InstantiationWithObjectManager.legacyClassname",
|
||||||
"type": "ERROR"
|
"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,
|
"column": 11,
|
||||||
"fixable": true,
|
"fixable": true,
|
||||||
|
@ -62,8 +44,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"totals": {
|
"totals": {
|
||||||
"errors": 6,
|
"errors": 4,
|
||||||
"fixable": 6,
|
"fixable": 4,
|
||||||
"warnings": 0
|
"warnings": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
}
|
Loading…
Reference in a new issue