PHP file comments.
Brought to you by:
hkodungallur,
tchule
Originally created by: mithesh....@clariontechnologies.co.in
How can we detect that each and every PHP file that is scanned using PHPcheckstyle has comment at the start as per PHP standards giving description of file along with other required parameters.
Can you please help me on this urgently.
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: tch...@hotmail.com
There is a (somewhat) related issue : https://code.google.com/p/phpcheckstyle/issues/detail?id=57
I think this is a completly new check to add.
We could add a special call to a "_processFileStart()" method, that would launch a "checkXXX" method that would detect the presence of the comment (just check that the next token is a comment).
There is already comment detection and annotations analysis for class/method (see _processComment) but it's a bit different.
I can have a look at that but I don't have a lot of spare time these days.
Tchule.
Status: Accepted
Related
Tickets: #57
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: mithesh....@clariontechnologies.co.in
First of all thanks for your quick reply.
Also thanks for the hint that you gave.
Yaa I have checked for _processComment method but its different.
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: tch...@hotmail.com
I have made a commit, can you have a look ?
I am not very sure for this one.
I check for the presence of a given string in the file, but I don't check that it's the start of the file and I ignore the spaces, tabs and returns (a few tests showed that spaces can generate false positives).
Status: Started
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: mithesh....@clariontechnologies.co.in
Hey Thanks,
I will check that for sure.
Also I have developed code for that and its working perfectly as per my requirements.
Will share that code as well.
But Thanks once again for replying and your time.
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: mithesh....@clariontechnologies.co.in
In _checkFileComments Function I made following changes -
$fileCount = count(file($this->_currentFilename));
// Limit this check for first 10 lines of file. It can be increased the number in else condition.
if ($fileCount <= 11 ) {
//echo $fileCount . '<br/>';
$limitLines = $fileCount - 3;
}
else {
$limitLines = 10;
}
// Test for '@file' in comment.
if (($this->_config->getTestProperty('noFileComment', 'testFile') != 'false')) {
if ($this->_docblocfile == 0 && $this->_orgLineNumber == $limitLines) {
//$msg = sprintf(PHPCHECKSTYLE_DOCBLOCK_RETURN, $this->_currentFunctionName);
//$this->_writeError('docBlocks', $msg);
$this->_writeError('noFileComment', "Doc block comments should include information about file(@file) for each PHP file.", "2");
}
}
Done following changes in _processComment function -
if (stripos($token->text, '@file') !== false) {
$this->_docblocfile++;
}
Done following changes in _processToken function -
if ($token->id == T_NEW_LINE) {
//echo $token->text;
$this->_checkFileComments();
$this->_orgLineNumber++;
}