FEATURE: Detect classes in strings
* Detect class names in strings. * Attach feature to new detection. * Only add warnings for classes in strings, they might be table names. Closes: #15
This commit is contained in:
parent
52b110c5a6
commit
afd6f78196
6 changed files with 128 additions and 1 deletions
|
@ -9,6 +9,7 @@ Typo3Update\Feature\LegacyClassnameFeature:
|
|||
- Typo3Update_Sniffs_Classname_MissingVendorForPluginsAndModulesSniff
|
||||
- Typo3Update_Sniffs_Classname_PhpDocCommentSniff
|
||||
- Typo3Update_Sniffs_Classname_StaticCallSniff
|
||||
- Typo3Update_Sniffs_Classname_StringSniff
|
||||
- Typo3Update_Sniffs_Classname_TypeHintCatchExceptionSniff
|
||||
- Typo3Update_Sniffs_Classname_TypeHintSniff
|
||||
- Typo3Update_Sniffs_Classname_UseSniff
|
||||
|
|
|
@ -96,6 +96,10 @@ class LegacyClassnameFeature implements FeatureInterface
|
|||
*/
|
||||
protected function isLegacyClassname($classname)
|
||||
{
|
||||
if (get_class($this->sniff) === \Typo3Update_Sniffs_Classname_StringSniff::class) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->legacyMapping->isLegacyClassname($classname);
|
||||
}
|
||||
|
||||
|
@ -117,7 +121,9 @@ class LegacyClassnameFeature implements FeatureInterface
|
|||
return $nameParts[1];
|
||||
}, $classname);
|
||||
|
||||
if (!in_array($extensionName, $this->legacyExtensions)) {
|
||||
if (!in_array($extensionName, $this->legacyExtensions)
|
||||
&& get_class($this->sniff) !== \Typo3Update_Sniffs_Classname_StringSniff::class
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
53
src/Standards/Typo3Update/Sniffs/Classname/StringSniff.php
Normal file
53
src/Standards/Typo3Update/Sniffs/Classname/StringSniff.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
use PHP_CodeSniffer_File as PhpCsFile;
|
||||
use PHP_CodeSniffer_Sniff as PhpCsSniff;
|
||||
use PHP_CodeSniffer_Tokens as PhpCsTokens;
|
||||
use Typo3Update\Feature\FeaturesSupport;
|
||||
|
||||
class Typo3Update_Sniffs_Classname_StringSniff implements PhpCsSniff
|
||||
{
|
||||
use FeaturesSupport;
|
||||
|
||||
/**
|
||||
* @return array<int>
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return PhpCsTokens::$stringTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PhpCsFile $phpcsFile
|
||||
* @param int $stackPtr
|
||||
*/
|
||||
public function process(PhpCsFile $phpcsFile, $stackPtr)
|
||||
{
|
||||
$token = $phpcsFile->getTokens()[$stackPtr]['content'];
|
||||
// Special chars like ":" and "&" are used in configuration directives.
|
||||
$classnames = array_filter(preg_split('/\s+|:|>|-|&/', substr($token, 1, -1)));
|
||||
|
||||
foreach ($classnames as $classname) {
|
||||
$this->processFeatures($phpcsFile, $stackPtr, $classname);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"files": {
|
||||
"InputFileForIssues.php": {
|
||||
"errors": 0,
|
||||
"messages": [
|
||||
{
|
||||
"column": 80,
|
||||
"fixable": false,
|
||||
"line": 22,
|
||||
"message": "Legacy classes are not allowed; found Tx_Extbase_Command_HelpCommandController that might be a legacy class that does not exist anymore",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.mightBeLegacyClassname",
|
||||
"type": "WARNING"
|
||||
},
|
||||
{
|
||||
"column": 80,
|
||||
"fixable": false,
|
||||
"line": 23,
|
||||
"message": "Legacy classes are not allowed; found Tx_Extbase_Command_HelpCommandController that might be a legacy class that does not exist anymore",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.mightBeLegacyClassname",
|
||||
"type": "WARNING"
|
||||
},
|
||||
{
|
||||
"column": 93,
|
||||
"fixable": false,
|
||||
"line": 25,
|
||||
"message": "Legacy classes are not allowed; found Tx_ExtKey_Hooks_Cache that might be a legacy class that does not exist anymore",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.mightBeLegacyClassname",
|
||||
"type": "WARNING"
|
||||
}
|
||||
],
|
||||
"warnings": 3
|
||||
}
|
||||
},
|
||||
"totals": {
|
||||
"errors": 0,
|
||||
"fixable": 0,
|
||||
"warnings": 3
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Tx_Extbase_Command_HelpCommandController';
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "Tx_Extbase_Command_HelpCommandController";
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = 'EXT:ext_key/Classes/Hooks/Cache.php:&Tx_ExtKey_Hooks_Cache->getHash';
|
Loading…
Reference in a new issue