From f2910b02b275d28bb1bf7514c8bf2e542cecf06f Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 11 May 2017 11:17:46 +0200 Subject: [PATCH 1/2] BUGFIX: Allow PhpDocCommentSniff to work find all classnames in comment * Before only the first classname was returned. * All class names are returned now. * This allows to fix Extbase type annotations for relations. --- .../Sniffs/Classname/PhpDocCommentSniff.php | 2 +- .../PhpDocCommentSniff/Expected.diff | 15 ++++++--- .../PhpDocCommentSniff/Expected.json | 32 +++++++++++++++---- .../PhpDocCommentSniff/InputFileForIssues.php | 9 ++++-- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php index d1f7f78..13dd59f 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php @@ -69,7 +69,7 @@ class Typo3Update_Sniffs_Classname_PhpDocCommentSniff implements PhpCsSniff if ($classnamePosition === false) { return; } - $classnames = explode('|', explode(' ', $tokens[$classnamePosition]['content'])[0]); + $classnames = array_filter(preg_split('/\||\s|\<|\>/', $tokens[$classnamePosition]['content'])); foreach ($classnames as $classname) { $this->processFeatures($phpcsFile, $classnamePosition, $classname); diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff index 36a8cf7..866ee24 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -22,20 +22,20 @@ +@@ -22,25 +22,25 @@ class InputFileForIssues { /** @@ -10,6 +10,12 @@ */ protected $someVar; + /** +- * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage ++ * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> + */ + protected $someRelation; + /** - * @param t3lib_div + * @param \TYPO3\CMS\Core\Utility\GeneralUtility @@ -20,8 +26,9 @@ */ public function doSomething($something) { -- /** @var t3lib_div $variable */ // This is supported as this is a phpdoc. -+ /** @var \TYPO3\CMS\Core\Utility\GeneralUtility $variable */ // This is supported as this is a phpdoc. - /** @var $variable t3lib_div */ // This is not supported! Use inline comments instead. +- /** @var t3lib_div $variable */ +- /** @var $variable t3lib_div */ ++ /** @var \TYPO3\CMS\Core\Utility\GeneralUtility $variable */ ++ /** @var $variable \TYPO3\CMS\Core\Utility\GeneralUtility */ } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json index 89158c7..e18619b 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json @@ -1,7 +1,7 @@ { "files": { "InputFileForIssues.php": { - "errors": 4, + "errors": 6, "messages": [ { "column": 13, @@ -13,9 +13,18 @@ "type": "ERROR" }, { - "column": 15, + "column": 13, "fixable": true, "line": 31, + "message": "Legacy classes are not allowed; found \"Tx_Extbase_Domain_Model_Category\", use \"TYPO3\\CMS\\Extbase\\Domain\\Model\\Category\" instead", + "severity": 5, + "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", + "type": "ERROR" + }, + { + "column": 15, + "fixable": true, + "line": 36, "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", @@ -24,7 +33,7 @@ { "column": 15, "fixable": false, - "line": 32, + "line": 37, "message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Template\\MediumDocumentTemplate. Removed in 7.0. Use \\TYPO3\\CMS\\Backend\\Template\\DocumentTemplate instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-61782-DeprecatedDocumentTemplateClassesRemoved.html", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.RemovedClass.TYPO3_CMS_Backend_Template_MediumDocumentTemplate", @@ -33,7 +42,7 @@ { "column": 16, "fixable": true, - "line": 34, + "line": 39, "message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", @@ -42,7 +51,16 @@ { "column": 18, "fixable": true, - "line": 38, + "line": 43, + "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", + "severity": 5, + "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", + "type": "ERROR" + }, + { + "column": 18, + "fixable": true, + "line": 44, "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", @@ -53,8 +71,8 @@ } }, "totals": { - "errors": 4, - "fixable": 4, + "errors": 6, + "fixable": 6, "warnings": 1 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php index 7a2de67..cf0f24d 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php @@ -27,6 +27,11 @@ class InputFileForIssues */ protected $someVar; + /** + * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage + */ + protected $someRelation; + /** * @param t3lib_div * @param \TYPO3\CMS\Backend\Template\MediumDocumentTemplate @@ -35,7 +40,7 @@ class InputFileForIssues */ public function doSomething($something) { - /** @var t3lib_div $variable */ // This is supported as this is a phpdoc. - /** @var $variable t3lib_div */ // This is not supported! Use inline comments instead. + /** @var t3lib_div $variable */ + /** @var $variable t3lib_div */ } } From 2d3165e8f4780f293f86b9f4650cf2ed8adfbf2d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 16 May 2017 10:36:27 +0200 Subject: [PATCH 2/2] BUGFIX: Also allow to fix validator classnames --- .../Sniffs/Classname/PhpDocCommentSniff.php | 4 +- src/Standards/Typo3Update/ruleset.xml | 2 +- .../PhpDocCommentSniff/Expected.diff | 4 +- .../PhpDocCommentSniff/Expected.json | 39 ++++++++++++------- .../PhpDocCommentSniff/InputFileForIssues.php | 1 + 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php index 13dd59f..f00fd12 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff.php @@ -38,7 +38,7 @@ class Typo3Update_Sniffs_Classname_PhpDocCommentSniff implements PhpCsSniff * The configured tags will be processed. * @var array */ - public $allowedTags = ['@param', '@return', '@var']; + public $allowedTags = ['@param', '@return', '@var', '@validate']; /** * Returns the token types that this sniff is interested in. @@ -69,7 +69,7 @@ class Typo3Update_Sniffs_Classname_PhpDocCommentSniff implements PhpCsSniff if ($classnamePosition === false) { return; } - $classnames = array_filter(preg_split('/\||\s|\<|\>/', $tokens[$classnamePosition]['content'])); + $classnames = array_filter(preg_split('/\||\s|\<|\>|\(/', $tokens[$classnamePosition]['content'])); foreach ($classnames as $classname) { $this->processFeatures($phpcsFile, $classnamePosition, $classname); diff --git a/src/Standards/Typo3Update/ruleset.xml b/src/Standards/Typo3Update/ruleset.xml index f9e1580..5ec5d5d 100644 --- a/src/Standards/Typo3Update/ruleset.xml +++ b/src/Standards/Typo3Update/ruleset.xml @@ -9,7 +9,7 @@ - + diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff index 866ee24..2efed23 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -22,25 +22,25 @@ +@@ -22,26 +22,26 @@ class InputFileForIssues { /** @@ -12,7 +12,9 @@ /** - * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage +- * @validate Tx_Extbase_Validation_Validator_NumberValidator(property="value") + * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> ++ * @validate \TYPO3\CMS\Extbase\Validation\Validator\NumberValidator(property="value") */ protected $someRelation; diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json index e18619b..d06c907 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json @@ -1,7 +1,7 @@ { "files": { "InputFileForIssues.php": { - "errors": 6, + "errors": 7, "messages": [ { "column": 13, @@ -21,10 +21,19 @@ "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", "type": "ERROR" }, + { + "column": 18, + "fixable": true, + "line": 32, + "message": "Legacy classes are not allowed; found \"Tx_Extbase_Validation_Validator_NumberValidator\", use \"TYPO3\\CMS\\Extbase\\Validation\\Validator\\NumberValidator\" instead", + "severity": 5, + "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", + "type": "ERROR" + }, { "column": 15, "fixable": true, - "line": 36, + "line": 37, "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", @@ -33,7 +42,7 @@ { "column": 15, "fixable": false, - "line": 37, + "line": 38, "message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Template\\MediumDocumentTemplate. Removed in 7.0. Use \\TYPO3\\CMS\\Backend\\Template\\DocumentTemplate instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-61782-DeprecatedDocumentTemplateClassesRemoved.html", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.RemovedClass.TYPO3_CMS_Backend_Template_MediumDocumentTemplate", @@ -42,21 +51,12 @@ { "column": 16, "fixable": true, - "line": 39, + "line": 40, "message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", "type": "ERROR" }, - { - "column": 18, - "fixable": true, - "line": 43, - "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", - "severity": 5, - "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", - "type": "ERROR" - }, { "column": 18, "fixable": true, @@ -65,14 +65,23 @@ "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", "type": "ERROR" + }, + { + "column": 18, + "fixable": true, + "line": 45, + "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", + "severity": 5, + "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", + "type": "ERROR" } ], "warnings": 1 } }, "totals": { - "errors": 6, - "fixable": 6, + "errors": 7, + "fixable": 7, "warnings": 1 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php index cf0f24d..6146222 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php @@ -29,6 +29,7 @@ class InputFileForIssues /** * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage + * @validate Tx_Extbase_Validation_Validator_NumberValidator(property="value") */ protected $someRelation;