Merge branch 'hotfix/allow-phpdoc-to-substitute-all-classnames' into 'develop'

BUGFIX: Allow PhpDocCommentSniff to work find all classnames in comment

See merge request !92
This commit is contained in:
Daniel Hürtgen 2017-05-16 14:44:56 +02:00
commit ec7a4634c9
5 changed files with 58 additions and 16 deletions

View file

@ -38,7 +38,7 @@ class Typo3Update_Sniffs_Classname_PhpDocCommentSniff implements PhpCsSniff
* The configured tags will be processed. * The configured tags will be processed.
* @var array<string> * @var array<string>
*/ */
public $allowedTags = ['@param', '@return', '@var']; public $allowedTags = ['@param', '@return', '@var', '@validate'];
/** /**
* Returns the token types that this sniff is interested in. * Returns the token types that this sniff is interested in.
@ -69,7 +69,7 @@ class Typo3Update_Sniffs_Classname_PhpDocCommentSniff implements PhpCsSniff
if ($classnamePosition === false) { if ($classnamePosition === false) {
return; return;
} }
$classnames = explode('|', explode(' ', $tokens[$classnamePosition]['content'])[0]); $classnames = array_filter(preg_split('/\||\s|\<|\>|\(/', $tokens[$classnamePosition]['content']));
foreach ($classnames as $classname) { foreach ($classnames as $classname) {
$this->processFeatures($phpcsFile, $classnamePosition, $classname); $this->processFeatures($phpcsFile, $classnamePosition, $classname);

View file

@ -9,7 +9,7 @@
</rule> </rule>
<rule ref="Typo3Update.Classname.PhpDocComment"> <rule ref="Typo3Update.Classname.PhpDocComment">
<properties> <properties>
<property name="allowedTags" type="array" value="@param,@return,@var,@see,@throws"/> <property name="allowedTags" type="array" value="@param,@return,@var,@validate,@see,@throws"/>
</properties> </properties>
</rule> </rule>
</ruleset> </ruleset>

View file

@ -1,6 +1,6 @@
--- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php
+++ PHP_CodeSniffer +++ PHP_CodeSniffer
@@ -22,20 +22,20 @@ @@ -22,26 +22,26 @@
class InputFileForIssues class InputFileForIssues
{ {
/** /**
@ -10,6 +10,14 @@
*/ */
protected $someVar; protected $someVar;
/**
- * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<Tx_Extbase_Domain_Model_Category>
- * @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;
/** /**
- * @param t3lib_div - * @param t3lib_div
+ * @param \TYPO3\CMS\Core\Utility\GeneralUtility + * @param \TYPO3\CMS\Core\Utility\GeneralUtility
@ -20,8 +28,9 @@
*/ */
public function doSomething($something) public function doSomething($something)
{ {
- /** @var t3lib_div $variable */ // This is supported as this is a phpdoc. - /** @var t3lib_div $variable */
+ /** @var \TYPO3\CMS\Core\Utility\GeneralUtility $variable */ // This is supported as this is a phpdoc. - /** @var $variable t3lib_div */
/** @var $variable t3lib_div */ // This is not supported! Use inline comments instead. + /** @var \TYPO3\CMS\Core\Utility\GeneralUtility $variable */
+ /** @var $variable \TYPO3\CMS\Core\Utility\GeneralUtility */
} }
} }

View file

@ -1,7 +1,7 @@
{ {
"files": { "files": {
"InputFileForIssues.php": { "InputFileForIssues.php": {
"errors": 4, "errors": 7,
"messages": [ "messages": [
{ {
"column": 13, "column": 13,
@ -13,9 +13,27 @@
"type": "ERROR" "type": "ERROR"
}, },
{ {
"column": 15, "column": 13,
"fixable": true, "fixable": true,
"line": 31, "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": 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": 37,
"message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead",
"severity": 5, "severity": 5,
"source": "Typo3Update.Classname.PhpDocComment.legacyClassname", "source": "Typo3Update.Classname.PhpDocComment.legacyClassname",
@ -24,7 +42,7 @@
{ {
"column": 15, "column": 15,
"fixable": false, "fixable": false,
"line": 32, "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", "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, "severity": 5,
"source": "Typo3Update.Classname.PhpDocComment.RemovedClass.TYPO3_CMS_Backend_Template_MediumDocumentTemplate", "source": "Typo3Update.Classname.PhpDocComment.RemovedClass.TYPO3_CMS_Backend_Template_MediumDocumentTemplate",
@ -33,7 +51,7 @@
{ {
"column": 16, "column": 16,
"fixable": true, "fixable": true,
"line": 34, "line": 40,
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead", "message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead",
"severity": 5, "severity": 5,
"source": "Typo3Update.Classname.PhpDocComment.legacyClassname", "source": "Typo3Update.Classname.PhpDocComment.legacyClassname",
@ -42,7 +60,16 @@
{ {
"column": 18, "column": 18,
"fixable": true, "fixable": true,
"line": 38, "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",
"type": "ERROR"
},
{
"column": 18,
"fixable": true,
"line": 45,
"message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead",
"severity": 5, "severity": 5,
"source": "Typo3Update.Classname.PhpDocComment.legacyClassname", "source": "Typo3Update.Classname.PhpDocComment.legacyClassname",
@ -53,8 +80,8 @@
} }
}, },
"totals": { "totals": {
"errors": 4, "errors": 7,
"fixable": 4, "fixable": 7,
"warnings": 1 "warnings": 1
} }
} }

View file

@ -27,6 +27,12 @@ class InputFileForIssues
*/ */
protected $someVar; protected $someVar;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<Tx_Extbase_Domain_Model_Category>
* @validate Tx_Extbase_Validation_Validator_NumberValidator(property="value")
*/
protected $someRelation;
/** /**
* @param t3lib_div * @param t3lib_div
* @param \TYPO3\CMS\Backend\Template\MediumDocumentTemplate * @param \TYPO3\CMS\Backend\Template\MediumDocumentTemplate
@ -35,7 +41,7 @@ class InputFileForIssues
*/ */
public function doSomething($something) public function doSomething($something)
{ {
/** @var t3lib_div $variable */ // This is supported as this is a phpdoc. /** @var t3lib_div $variable */
/** @var $variable t3lib_div */ // This is not supported! Use inline comments instead. /** @var $variable t3lib_div */
} }
} }