PHP short tag check
Does PHPMD have a check for php files that are using short tag form? <? instead of <?php
Hi @johnwc, no it doesn't. Feel free to propose a pull-request for this.
@kylekatarnls I see this is marked "Good first issue" though I'm having trouble finding any metric or even getting a custom rule's apply invoked. Do I need to fork PDepend to create an 'aware' and/or metric for opening short tags?
Any other info or pointers on how to begin would be appreciated.
Hello,
Indeed, PDepend needs to support it first. It contains a src/main/php/PDepend/Source/Language/PHP/PHPTokenizerInternal.php file who run token_get_all($source) inside the tokenize() method. token_get_all return following tokens that concern this issue:
-
T_INLINE_HTMLfor<? -
T_OPEN_TAGfor<?php -
T_OPEN_TAG_WITH_ECHOfor<?=
And it contains:
$source = preg_replace(
array('(<\?=)', '(<\?(\s))'),
array('<?php echo ', '<?php\1'),
$source
);
This replacement (which is not really needed) should be removed so we can detect each token in src/main/php/PDepend/Source/Language/PHP/AbstractPHPParser.php in the parse() method.
In the switch Tokens::T_INLINE_HTML will need to be added in the same case than Tokens::T_OPEN_TAG. In this case and the Tokens::T_CLOSE_TAG one (or until Tokenizer::T_EOF) we could record in an array the list PHP code chunks and the informations for start and end of each: file, line, token type, so PHPMD can use this list to raise rule violations if the type is forbidden.
@kylekatarnls I've prepared pdepend/pdepend#490 though not sure where the docs are within that repo in order to update them. Do you have any insight on where I should look?