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:
Daniel Siepmann 2017-04-06 12:35:44 +02:00
parent af74a5db21
commit 03f321c865
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
6 changed files with 91 additions and 23 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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
}
}

View file

@ -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
}

View file

@ -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
}
}

View file

@ -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
}