*/ protected $targetFunctions = [ 'ldap_connect' => true, ]; /** * Do a version check to determine if this sniff needs to run at all. * * @since 10.0.0 * * @return bool */ protected function bowOutEarly() { return (ScannedCode::shouldRunOnOrAbove('8.3') === false); } /** * Process the parameters of a matched function. * * @since 10.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in the stack. * @param string $functionName The token content (function name) which was matched. * @param array $parameters Array with information about the parameters. * * @return int|void Integer stack pointer to skip forward or void to continue * normal file processing. */ public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) { if (ScannedCode::shouldRunOnOrAbove('8.4') === true) { /* * On PHP 8.4, the 3+ param signature is deprecated. */ $walletParam = PassedParameters::getParameterFromStack($parameters, 3, 'wallet'); $passwordParam = PassedParameters::getParameterFromStack($parameters, 4, 'password'); $authmodeParam = PassedParameters::getParameterFromStack($parameters, 5, 'auth_mode'); if ($walletParam !== false || $passwordParam !== false || $authmodeParam !== false) { // Found a 3+ param signature. $phpcsFile->addWarning( 'Calling ldap_connect() with three or more parameters is deprecated since PHP 8.4. Use ldap_connect_wallet() (PHP 8.3+) instead.', $stackPtr, 'DeprecatedThreePlusParamSignature' ); /* * If this notice has been thrown, we shouldn't throw the PHP 8.3 related notice for 3+ param * signatures as the "do this instead" advise conflicts. */ return; } } /* * On PHP 8.3, the 2-param signature is deprecated, including passing a non-null $port value * when using the 3+ param signature. */ $uriParam = PassedParameters::getParameterFromStack($parameters, 1, ['uri', 'host']); $portParam = PassedParameters::getParameterFromStack($parameters, 2, 'port'); if ($uriParam === false || $portParam === false) { // Not the deprecated two param signature. return; } // Check for the, still supported, 3+ param signature and if found, check the second param is `null`. if (\count($parameters) > 2) { $hasVariableContent = $phpcsFile->findNext([\T_VARIABLE, \T_STRING], $portParam['start'], ($portParam['end'] + 1)); if ($hasVariableContent !== false) { // We don't have access to the contents of the parameter. Bow out. return; } if ($portParam['clean'] === 'null') { // This is the correct value to still use the 3+ param signature. Bow out. return; } // Found a 3+ param signature, which doesn't pass `null` as $port. $phpcsFile->addWarning( 'Calling ldap_connect() with a $port which is not `null` is deprecated since PHP 8.3. Call ldap_connect() with an LDAP-URI as the $uri parameter and pass `null` for $port instead.', $stackPtr, 'DeprecatedPortNotNull' ); return; } // Found the deprecated 2-param signature. $phpcsFile->addWarning( 'Calling ldap_connect() with two parameters is deprecated since PHP 8.3. Call ldap_connect() with an LDAP-URI as the first (and only) parameter instead.', $stackPtr, 'DeprecatedTwoParamSignature' ); } }