Closed witrin closed 9 years ago
Thus to get rid of this bug I need currently to use this in my custom ruleset:
<?xml version="1.0"?>
<ruleset name="[...]">
[...]
<rule ref="TYPO3CMS">
[...]
<!-- see https://github.com/typo3-ci/TYPO3SniffPool/issues/54 -->
<exclude name="TYPO3SniffPool.Scope.AlwaysReturn" />
</rule>
</ruleset>
Please provide the code of the file in question. I will try to reproduce the error.
I'm able to reproduce here but I can't post the whole project so hopefully this helps:
<?php
/**
* Bar
*/
class Bar {
public function foo() {
}
}
FILE: ...src/Classes/Domain/Repository/Bar.php
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
1 | ERROR | An error occurred during processing; checking has been aborted.
| | The error message was: Token type is not T_FUNCTION, T_CLASS,
| | T_INTERFACE or T_TRAIT (unknownSniff)
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------
[...]
Warning: PHP Notice: Undefined offset: 34 in ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/TYPO3SniffPool/Sniffs/Scope/AlwaysReturnSniff.php on line 103
PHP Stack trace:
PHP 1. {main}() ~/.composer/vendor/squizlabs/php_codesniffer/scripts/phpcs:0
PHP 2. PHP_CodeSniffer_CLI->process() ~/.composer/vendor/squizlabs/php_codesniffer/scripts/phpcs:37
PHP 3. PHP_CodeSniffer->process() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/CLI.php:647
PHP 4. PHP_CodeSniffer->processFile() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php:488
PHP 5. PHP_CodeSniffer->_processFile() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1351
PHP 6. PHP_CodeSniffer_File->start() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1471
PHP 7. TYPO3SniffPool_Sniffs_Scope_AlwaysReturnSniff->process() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/File.php:509
PHP Notice: Undefined offset: 34 in ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/File.php on line 2074
PHP Stack trace:
PHP 1. {main}() ~/.composer/vendor/squizlabs/php_codesniffer/scripts/phpcs:0
PHP 2. PHP_CodeSniffer_CLI->process() ~/.composer/vendor/squizlabs/php_codesniffer/scripts/phpcs:37
PHP 3. PHP_CodeSniffer->process() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/CLI.php:647
PHP 4. PHP_CodeSniffer->processFile() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php:488
PHP 5. PHP_CodeSniffer->_processFile() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1351
PHP 6. PHP_CodeSniffer_File->start() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1471
PHP 7. TYPO3SniffPool_Sniffs_Scope_AlwaysReturnSniff->process() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/File.php:509
PHP 8. PHP_CodeSniffer_File->getDeclarationName() ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/TYPO3SniffPool/Sniffs/Scope/AlwaysReturnSniff.php:106
<?php
/**
* Bar
*/
class Bar {
/**
* Baz
*/
public function foo() {
}
}
FILE: ...src/Classes/Domain/Repository/Bar.php
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
11 | ERROR | This function must always have a return value.
| | (TYPO3SniffPool.Scope.AlwaysReturn.AlwaysReturnStatement)
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------
$ phpcs --version
PHP_CodeSniffer version 1.5.6 (stable) by Squiz (http://www.squiz.net)
Thanks for providing these informations. Can you install the latest development version of the CGL? If you installed the CGL by Composer add/modify the composer.json as follows:
{
"minimum-stability": "dev",
"require": {
"typo3-ci/typo3cms": "dev-develop"
}
}
In this version the AlwaysReturnSniff is deactivated as you already did by youself - but even if I reactivate the sniff I can't reproduce the error.
With the latest development version the error is gone even with AlwaysReturnSniff
activated.
I ran into the same issue again (see #35) but this time its not in the unit tests so I can't ignore it. The only helpful hint I've found so far was from Greg Sherwood (http://pear.php.net/bugs/bug.php?id=15336). So I removed one sniff after another from the
TYPO3CMS
ruleset and after I removed<rule ref="../TYPO3SniffPool/Sniffs/Scope/AlwaysReturnSniff.php" />
the aborting error was gone, so there must be a bug in Sniffs/Scope/AlwaysReturnSniff.php. Unfortunately I'm not familiar with this stuff and the sniff is not very small...