timw4mail /
HummingBirdAnimeClient
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * CodeIgniter_Sniffs_NamingConventions_ConstructorNameSniff. |
||
| 4 | * |
||
| 5 | * PHP version 5 |
||
| 6 | * |
||
| 7 | * @category PHP |
||
| 8 | * @package PHP_CodeSniffer |
||
| 9 | * @author Thomas Ernest <[email protected]> |
||
| 10 | * @copyright 2011 Thomas Ernest |
||
| 11 | * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License |
||
| 12 | * @link http://pear.php.net/package/PHP_CodeSniffer |
||
| 13 | */ |
||
| 14 | |||
| 15 | namespace CodeIgniter\Sniffs\NamingConventions; |
||
| 16 | |||
| 17 | use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; |
||
| 18 | use PHP_CodeSniffer\Files\File; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * CodeIgniter_Sniffs_NamingConventions_ConstructorNameSniff. |
||
| 22 | * |
||
| 23 | * Favor PHP 4 constructor syntax, which uses "function ClassName()". |
||
| 24 | * Avoid PHP 5 constructor syntax, which uses "function __construct()". |
||
| 25 | * |
||
| 26 | * @todo Try to avoid overly long and verbose names. |
||
| 27 | * |
||
| 28 | * @category PHP |
||
| 29 | * @package PHP_CodeSniffer |
||
| 30 | * @author Thomas Ernest <[email protected]> |
||
| 31 | * @copyright 2010 Thomas Ernest |
||
| 32 | * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License |
||
| 33 | * @link http://pear.php.net/package/PHP_CodeSniffer |
||
| 34 | */ |
||
| 35 | class ConstructorNameSniff extends AbstractScopeSniff |
||
| 36 | { |
||
| 37 | |||
| 38 | |||
| 39 | public $php5Constructors = '1'; |
||
| 40 | |||
| 41 | |||
| 42 | /** |
||
| 43 | * Constructs the test with the tokens it wishes to listen for. |
||
| 44 | * |
||
| 45 | * @return void |
||
|
0 ignored issues
–
show
|
|||
| 46 | */ |
||
| 47 | public function __construct() |
||
| 48 | { |
||
| 49 | parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true); |
||
| 50 | |||
| 51 | }//end __construct() |
||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * Processes this test when one of its tokens is encountered. |
||
| 56 | * |
||
| 57 | * @param File $phpcsFile The current file being scanned. |
||
| 58 | * @param int $stackPtr The position of the current token |
||
| 59 | * in the stack passed in $tokens. |
||
| 60 | * @param int $currScope A pointer to the start of the scope. |
||
| 61 | * |
||
| 62 | * @return void |
||
| 63 | */ |
||
| 64 | protected function processTokenWithinScope( |
||
| 65 | File $phpcsFile, |
||
| 66 | $stackPtr, |
||
| 67 | $currScope |
||
| 68 | ) { |
||
| 69 | $methodName = $phpcsFile->getDeclarationName($stackPtr); |
||
| 70 | $className = $phpcsFile->getDeclarationName($currScope); |
||
| 71 | |||
| 72 | $isPhp4Constructor = strcasecmp($methodName, $className) === 0; |
||
| 73 | $isPhp5Constructor = strcasecmp($methodName, '__construct') === 0; |
||
| 74 | if ($this->php5Constructors != '0') { |
||
| 75 | if ($isPhp4Constructor) { |
||
| 76 | $error = "PHP4 style constructors are not allowed; use \"__construct\" instead"; |
||
| 77 | $phpcsFile->addError($error, $stackPtr); |
||
|
0 ignored issues
–
show
|
|||
| 78 | } |
||
| 79 | } else { |
||
| 80 | if ($isPhp5Constructor) { |
||
| 81 | $error = "PHP5 style constructors are not allowed; use \"$className\" instead"; |
||
| 82 | $phpcsFile->addError($error, $stackPtr); |
||
|
0 ignored issues
–
show
|
|||
| 83 | } |
||
| 84 | } |
||
| 85 | if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) { |
||
| 86 | return; |
||
| 87 | } |
||
| 88 | |||
| 89 | $tokens = $phpcsFile->getTokens(); |
||
| 90 | |||
| 91 | $parentClassName = $phpcsFile->findExtendedClassName($currScope); |
||
| 92 | $wrongConstructor = ''; |
||
| 93 | // prepares the error message and wrong constructor |
||
| 94 | if ($this->php5Constructors != '0') { |
||
| 95 | $error = 'PHP4 style calls to parent constructors are not allowed.'; |
||
| 96 | $error = "$error Please use \"parent::__construct\" instead."; |
||
| 97 | if (false !== $parentClassName) { |
||
| 98 | $wrongConstructor = $parentClassName; |
||
| 99 | } |
||
| 100 | // Else $wrongConstructor will be empty |
||
| 101 | // and the test expression will always be false. |
||
| 102 | // It doesn't check that no parent method should be called |
||
| 103 | // when no parent class is defined. |
||
| 104 | } else { |
||
| 105 | $error = 'PHP5 style calls to parent constructors are not allowed.'; |
||
| 106 | if (false !== $parentClassName) { |
||
| 107 | $error = "$error Please use \"parent::$parentClassName\" instead."; |
||
| 108 | } |
||
| 109 | $wrongConstructor = '__construct'; |
||
| 110 | } |
||
| 111 | |||
| 112 | // looks for the use of a wrong constructor. |
||
| 113 | $endFunctionIndex = $tokens[$stackPtr]['scope_closer']; |
||
| 114 | $doubleColonIndex = $phpcsFile->findNext( |
||
| 115 | array(T_DOUBLE_COLON), |
||
| 116 | $stackPtr, |
||
| 117 | $endFunctionIndex |
||
| 118 | ); |
||
| 119 | while ($doubleColonIndex) { |
||
|
0 ignored issues
–
show
The expression
$doubleColonIndex of type integer|false is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
Loading history...
|
|||
| 120 | if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING |
||
| 121 | && $tokens[($doubleColonIndex + 1)]['content'] === $wrongConstructor |
||
| 122 | ) { |
||
| 123 | $phpcsFile->addError($error, ($doubleColonIndex + 1)); |
||
|
0 ignored issues
–
show
|
|||
| 124 | } |
||
| 125 | |||
| 126 | $doubleColonIndex = $phpcsFile->findNext( |
||
| 127 | array(T_DOUBLE_COLON), |
||
| 128 | $doubleColonIndex + 1, |
||
| 129 | $endFunctionIndex |
||
| 130 | ); |
||
| 131 | } |
||
| 132 | |||
| 133 | }//end processTokenWithinScope() |
||
| 134 | |||
| 135 | protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
||
| 136 | { |
||
| 137 | // TODO: Implement processTokenOutsideScope() method. |
||
| 138 | } |
||
| 139 | |||
| 140 | }//end class |
||
| 141 | |||
| 142 | ?> |
||
|
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. Loading history...
|
|||
| 143 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.