Issue #3328454 by xjm, Bhanu951, jidrone, smustgrave: Replace most strpos() !== FALSE or === FALSE with str_contains()

merge-requests/3431/head
catch 2023-03-18 11:30:09 +00:00
parent e029e6cdb5
commit b3fac4a09f
149 changed files with 198 additions and 200 deletions

View File

@ -39,7 +39,7 @@ if (file_exists(__DIR__ . $url['path'])) {
// Work around the PHP bug.
$path = $url['path'];
$script = 'index.php';
if (strpos($path, '.php') !== FALSE) {
if (str_contains($path, '.php')) {
// Work backwards through the path to check if a script exists. Otherwise
// fallback to index.php.
do {

View File

@ -162,7 +162,7 @@ class ComponentGenerator {
}
// The package wasn't in the lock file, which means we need to tell the
// user. But there are some packages we want to exclude from this list.
elseif ($package_name !== 'php' && (strpos($package_name, 'drupal/core-') === FALSE)) {
elseif ($package_name !== 'php' && !str_contains($package_name, 'drupal/core-')) {
$not_in_core[$package_name] = $package_name;
}
@ -174,7 +174,7 @@ class ComponentGenerator {
// Reconcile dependencies on other Drupal components, so we can set the
// constraint to our current version.
if (strpos($package_name, 'drupal/core-') !== FALSE) {
if (str_contains($package_name, 'drupal/core-')) {
if ($stability === 'stable') {
// Set the constraint to ^maj.min.
$package_data['require'][$package_name] = SemanticVersion::majorMinorConstraint(\Drupal::VERSION);

View File

@ -201,7 +201,7 @@ class AppendOp extends AbstractOperation {
}
$data = file_get_contents($data_path->fullPath());
return strpos($contents, $data) !== FALSE;
return str_contains($contents, $data);
}
}

View File

@ -39,7 +39,7 @@ if (file_exists(__DIR__ . $url['path'])) {
// Work around the PHP bug.
$path = $url['path'];
$script = 'index.php';
if (strpos($path, '.php') !== FALSE) {
if (str_contains($path, '.php')) {
// Work backwards through the path to check if a script exists. Otherwise
// fallback to index.php.
do {

View File

@ -318,7 +318,7 @@ function install_begin_request($class_loader, &$install_state) {
// running tests. However, for security reasons, it is imperative that no
// installation be permitted using such a prefix.
$user_agent = $request->cookies->get('SIMPLETEST_USER_AGENT') ?: $request->server->get('HTTP_USER_AGENT');
if ($install_state['interactive'] && strpos($user_agent, 'simpletest') !== FALSE && !drupal_valid_test_ua()) {
if ($install_state['interactive'] && str_contains($user_agent, 'simpletest') && !drupal_valid_test_ua()) {
header($request->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
exit;
}

View File

@ -485,7 +485,7 @@ final class DocParser
'attribute_types' => array(),
'targets_literal' => null,
'targets' => Target::TARGET_ALL,
'is_annotation' => false !== strpos($docComment, '@Annotation'),
'is_annotation' => str_contains($docComment, '@Annotation'),
);
// verify that the class is really meant to be an annotation
@ -519,16 +519,16 @@ final class DocParser
$attribute = new Attribute();
$attribute->required = (false !== strpos($propertyComment, '@Required'));
$attribute->required = str_contains($propertyComment, '@Required');
$attribute->name = $property->name;
$attribute->type = (false !== strpos($propertyComment, '@var') && preg_match('/@var\s+([^\s]+)/',$propertyComment, $matches))
$attribute->type = (str_contains($propertyComment, '@var') && preg_match('/@var\s+([^\s]+)/',$propertyComment, $matches))
? $matches[1]
: 'mixed';
$this->collectAttributeTypeMetadata($metadata, $attribute);
// checks if the property has @Enum
if (false !== strpos($propertyComment, '@Enum')) {
if (str_contains($propertyComment, '@Enum')) {
$context = 'property ' . $class->name . "::\$" . $property->name;
self::$metadataParser->setTarget(Target::TARGET_PROPERTY);
@ -896,7 +896,7 @@ final class DocParser
{
$identifier = $this->Identifier();
if ( ! defined($identifier) && false !== strpos($identifier, '::') && '\\' !== $identifier[0]) {
if ( ! defined($identifier) && str_contains($identifier, '::') && '\\' !== $identifier[0]) {
[$className, $const] = explode('::', $identifier);
$alias = (false === $pos = strpos($className, '\\')) ? $className : substr($className, 0, $pos);

View File

@ -497,7 +497,7 @@ class Container implements ContainerInterface, ResetInterface {
$alternatives = [];
foreach ($keys as $key) {
$lev = levenshtein($search_key, $key);
if ($lev <= strlen($search_key) / 3 || strpos($key, $search_key) !== FALSE) {
if ($lev <= strlen($search_key) / 3 || str_contains($key, $search_key)) {
$alternatives[] = $key;
}
}

View File

@ -407,7 +407,7 @@ class OptimizedPhpArrayDumper extends Dumper {
elseif ($value instanceof Parameter) {
return $this->getParameterCall((string) $value);
}
elseif (is_string($value) && FALSE !== strpos($value, '%')) {
elseif (is_string($value) && str_contains($value, '%')) {
if (preg_match('/^%([^%]+)%$/', $value, $matches)) {
return $this->getParameterCall($matches[1]);
}

View File

@ -202,8 +202,7 @@ class PoItem {
if (isset($values['comment'])) {
$this->setComment($values['comment']);
}
if (isset($this->source) &&
strpos($this->source, self::DELIMITER) !== FALSE) {
if (isset($this->source) && str_contains($this->source, self::DELIMITER)) {
$this->setSource(explode(self::DELIMITER, $this->source));
$this->setTranslation(explode(self::DELIMITER, $this->translation ?? ''));
$this->setPlural(count($this->source) > 1);

View File

@ -401,7 +401,7 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface {
}
// Ensure the plurality is terminated.
if (strpos($line, ']') === FALSE) {
if (!str_contains($line, ']')) {
$this->errors[] = new FormattableMarkup('The translation stream %uri contains an error: invalid format for "msgstr[]" on line %line.', $log_vars);
return FALSE;
}

View File

@ -132,7 +132,7 @@ class PhpTransliteration implements TransliterationInterface {
// Replace question marks with a unique hash if necessary. This because
// mb_convert_encoding() replaces all invalid characters with a question
// mark.
if ($unknown_character != '?' && strpos($string, '?') !== FALSE) {
if ($unknown_character != '?' && str_contains($string, '?')) {
$hash = hash('sha256', $string);
$string = str_replace('?', $hash, $string);
}

View File

@ -49,7 +49,7 @@ class Tags {
* The encoded string.
*/
public static function encode($tag) {
if (strpos($tag, ',') !== FALSE || strpos($tag, '"') !== FALSE) {
if (str_contains($tag, ',') || str_contains($tag, '"')) {
return '"' . str_replace('"', '""', $tag) . '"';
}
return $tag;

View File

@ -189,7 +189,7 @@ class UrlHelper {
$query_delimiter_position = strpos($url, '?');
if ($scheme_delimiter_position !== FALSE && ($query_delimiter_position === FALSE || $scheme_delimiter_position < $query_delimiter_position)) {
// Split off the fragment, if any.
if (strpos($url, '#') !== FALSE) {
if (str_contains($url, '#')) {
[$url, $options['fragment']] = explode('#', $url, 2);
}

View File

@ -66,7 +66,7 @@ class Variable {
$output = $var ? 'TRUE' : 'FALSE';
}
elseif (is_string($var)) {
if (strpos($var, "\n") !== FALSE || strpos($var, "'") !== FALSE) {
if (str_contains($var, "\n") || str_contains($var, "'")) {
// If the string contains a line break or a single quote, use the
// double quote export mode. Encode backslash, dollar symbols, and
// double quotes and transform some common control characters.

View File

@ -190,7 +190,7 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
if (!$this->emailValidator->isValid($form_state->getValue('recipient')) && strpos($form_state->getValue('recipient'), ':mail') === FALSE) {
if (!$this->emailValidator->isValid($form_state->getValue('recipient')) && !str_contains($form_state->getValue('recipient'), ':mail')) {
// We want the literal %author placeholder to be emphasized in the error message.
$form_state->setErrorByName('recipient', $this->t('Enter a valid email address or use a token email address such as %author.', ['%author' => '[node:author:mail]']));
}

View File

@ -142,7 +142,7 @@ class AssetResolver implements AssetResolverInterface {
$options['license'] = $definition['license'];
// Files with a query string cannot be preprocessed.
if ($options['type'] === 'file' && $options['preprocess'] && strpos($options['data'], '?') !== FALSE) {
if ($options['type'] === 'file' && $options['preprocess'] && str_contains($options['data'], '?')) {
$options['preprocess'] = FALSE;
}

View File

@ -69,7 +69,7 @@ class CssCollectionRenderer implements AssetCollectionRendererInterface {
// Only add the cache-busting query string if this isn't an aggregate
// file.
if (!isset($css_asset['preprocessed'])) {
$query_string_separator = (strpos($css_asset['data'], '?') !== FALSE) ? '&' : '?';
$query_string_separator = str_contains($css_asset['data'], '?') ? '&' : '?';
$element['#attributes']['href'] .= $query_string_separator . $query_string;
}
break;

View File

@ -82,7 +82,7 @@ class JsCollectionRenderer implements AssetCollectionRendererInterface {
case 'file':
$query_string = $js_asset['version'] == -1 ? $default_query_string : 'v=' . $js_asset['version'];
$query_string_separator = (strpos($js_asset['data'], '?') !== FALSE) ? '&' : '?';
$query_string_separator = str_contains($js_asset['data'], '?') ? '&' : '?';
$element['#attributes']['src'] = $this->fileUrlGenerator->generateString($js_asset['data']);
// Only add the cache-busting query string if this isn't an aggregate
// file.

View File

@ -168,7 +168,7 @@ class CacheContextsManager {
// Extract the parameter if available.
$parameter = NULL;
$context_id = $context_token;
if (strpos($context_token, ':') !== FALSE) {
if (str_contains($context_token, ':')) {
[$context_id, $parameter] = explode(':', $context_token);
}
@ -176,7 +176,7 @@ class CacheContextsManager {
// - a period means they don't have a parent
// - a colon means they're not a specific value of a cache context
// hence no optimizations are possible.
if (strpos($context_token, '.') === FALSE && strpos($context_token, ':') === FALSE) {
if (!str_contains($context_token, '.') && !str_contains($context_token, ':')) {
$optimized_content_tokens[] = $context_token;
}
// Check cacheability. If the context defines a max-age of 0, then it
@ -199,7 +199,7 @@ class CacheContextsManager {
$ancestor_found = TRUE;
}
} while (!$ancestor_found && strpos($ancestor, '.') !== FALSE);
} while (!$ancestor_found && str_contains($ancestor, '.'));
if (!$ancestor_found) {
$optimized_content_tokens[] = $context_token;
}
@ -240,7 +240,7 @@ class CacheContextsManager {
foreach ($context_tokens as $context) {
$context_id = $context;
$parameter = NULL;
if (strpos($context, ':') !== FALSE) {
if (str_contains($context, ':')) {
[$context_id, $parameter] = explode(':', $context, 2);
}
$contexts_with_parameters[] = [$context_id, $parameter];

View File

@ -28,7 +28,7 @@ class CacheContextsPass implements CompilerPassInterface {
sort($cache_contexts);
foreach ($cache_contexts as $id) {
// Validate the hierarchy of non-root-level cache contexts.
if (strpos($id, '.') !== FALSE) {
if (str_contains($id, '.')) {
$parent = substr($id, 0, strrpos($id, '.'));
if (!in_array($parent, $cache_contexts)) {
throw new \InvalidArgumentException(sprintf('The service "%s" has an invalid service ID: the period indicates the hierarchy of cache contexts, therefore "%s" is considered the parent cache context, but no cache context service with that name was found.', $id, $parent));

View File

@ -291,7 +291,7 @@ class InstallCommand extends Command {
$alternatives = [];
foreach (array_keys($profiles) as $profile_name) {
$lev = levenshtein($install_profile, $profile_name);
if ($lev <= strlen($profile_name) / 4 || FALSE !== strpos($profile_name, $install_profile)) {
if ($lev <= strlen($profile_name) / 4 || str_contains($profile_name, $install_profile)) {
$alternatives[] = $profile_name;
}
}

View File

@ -93,7 +93,7 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
*/
public static function validateName($name) {
// The name must be namespaced by owner.
if (strpos($name, '.') === FALSE) {
if (!str_contains($name, '.')) {
throw new ConfigNameException("Missing namespace in Config object name $name.");
}
// The name must be shorter than Config::MAX_NAME_LENGTH characters.
@ -207,7 +207,7 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
*/
protected function validateKeys(array $data) {
foreach ($data as $key => $value) {
if (strpos($key, '.') !== FALSE) {
if (str_contains($key, '.')) {
throw new ConfigValueException("$key key contains a dot which is not supported.");
}
if (is_array($value)) {

View File

@ -203,7 +203,7 @@ class Condition extends ConditionBase {
return strpos($value, $condition['value']) === 0;
case 'CONTAINS':
return strpos($value, $condition['value']) !== FALSE;
return str_contains($value, $condition['value']);
case 'ENDS_WITH':
return substr($value, -strlen($condition['value'])) === (string) $condition['value'];

View File

@ -207,7 +207,7 @@ class Query extends QueryBase implements QueryInterface {
case 'CONTAINS':
$filter = static function ($name) use ($value, $prefix_length) {
$id = substr($name, $prefix_length);
return strpos($id, $value) !== FALSE;
return str_contains($id, $value);
};
break;

View File

@ -58,7 +58,7 @@ class ControllerResolver implements ControllerResolverInterface {
return $controller;
}
if (strpos($controller, ':') === FALSE) {
if (!str_contains($controller, ':')) {
if (function_exists($controller)) {
return $controller;
}
@ -106,7 +106,7 @@ class ControllerResolver implements ControllerResolverInterface {
[$class_or_service, $method] = explode(':', $controller, 2);
}
// Controller in the class::method notation.
elseif (strpos($controller, '::') !== FALSE) {
elseif (str_contains($controller, '::')) {
[$class_or_service, $method] = explode('::', $controller, 2);
}
else {

View File

@ -566,7 +566,7 @@ abstract class Connection {
$trim_chars .= ';';
}
$query = rtrim($query, $trim_chars);
if (strpos($query, ';') !== FALSE && empty($options['allow_delimiter_in_query'])) {
if (str_contains($query, ';') && empty($options['allow_delimiter_in_query'])) {
throw new \InvalidArgumentException('; is not supported in SQL strings. Use only one statement at a time.');
}

View File

@ -856,7 +856,7 @@ class Select extends Query implements SelectInterface {
else {
$table_string = $this->connection->escapeTable($table['table']);
// Do not attempt prefixing cross database / schema queries.
if (strpos($table_string, '.') === FALSE) {
if (!str_contains($table_string, '.')) {
$table_string = '{' . $table_string . '}';
}
}

View File

@ -288,7 +288,7 @@ class YamlFileLoader
if (isset($service['factory'])) {
if (is_string($service['factory'])) {
if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
if (str_contains($service['factory'], ':') && !str_contains($service['factory'], '::')) {
$parts = explode(':', $service['factory']);
$definition->setFactory(array($this->resolveServices('@'.$parts[0]), $parts[1]));
} else {

View File

@ -103,7 +103,7 @@ class EntityRouteEnhancer implements EnhancerInterface {
*/
protected function enhanceEntityView(array $defaults, Request $request) {
$defaults['_controller'] = '\Drupal\Core\Entity\Controller\EntityViewController::view';
if (strpos($defaults['_entity_view'], '.') !== FALSE) {
if (str_contains($defaults['_entity_view'], '.')) {
// The _entity_view entry is of the form entity_type.view_mode.
[$entity_type, $view_mode] = explode('.', $defaults['_entity_view']);
$defaults['view_mode'] = $view_mode;

View File

@ -56,12 +56,12 @@ class EntityCreateAccessCheck implements AccessInterface {
// The bundle argument can contain request argument placeholders like
// {name}, loop over the raw variables and attempt to replace them in the
// bundle name. If a placeholder does not exist, it won't get replaced.
if ($bundle && strpos($bundle, '{') !== FALSE) {
if ($bundle && str_contains($bundle, '{')) {
foreach ($route_match->getRawParameters()->all() as $name => $value) {
$bundle = str_replace('{' . $name . '}', $value, $bundle);
}
// If we were unable to replace all placeholders, deny access.
if (strpos($bundle, '{') !== FALSE) {
if (str_contains($bundle, '{')) {
return AccessResult::neutral(sprintf("Could not find '%s' request argument, therefore cannot check create access.", $bundle));
}
}

View File

@ -42,7 +42,7 @@ class SelectionPluginManager extends DefaultPluginManager implements SelectionPl
];
// A specific selection plugin ID was already specified.
if (strpos($options['handler'], ':') !== FALSE) {
if (str_contains($options['handler'], ':')) {
$plugin_id = $options['handler'];
}
// Only a selection group name was specified.

View File

@ -86,7 +86,7 @@ class EntityResolverManager {
return NULL;
}
if (strpos($controller, ':') === FALSE) {
if (!str_contains($controller, ':')) {
if (method_exists($controller, '__invoke')) {
return [$controller, '__invoke'];
}
@ -105,7 +105,7 @@ class EntityResolverManager {
[$class_or_service, $method] = explode(':', $controller, 2);
return [$this->classResolver->getInstanceFromDefinition($class_or_service), $method];
}
elseif (strpos($controller, '::') !== FALSE) {
elseif (str_contains($controller, '::')) {
// Controller in the class::method notation.
return explode('::', $controller, 2);
}
@ -182,7 +182,7 @@ class EntityResolverManager {
// Do not add parameter information if the route does not declare a
// parameter in the first place. This is the case for add forms, for
// example.
if (isset($entity_type) && isset($this->getEntityTypes()[$entity_type]) && (strpos($route->getPath(), '{' . $entity_type . '}') !== FALSE)) {
if (isset($entity_type) && isset($this->getEntityTypes()[$entity_type]) && str_contains($route->getPath(), '{' . $entity_type . '}')) {
$parameter_definitions = $route->getOption('parameters') ?: [];
// First try to figure out whether there is already a parameter upcasting

View File

@ -119,7 +119,7 @@ class PhpSelection extends DefaultSelection {
return strpos($label, $match) === 0;
case 'CONTAINS':
return strpos($label, $match) !== FALSE;
return str_contains($label, $match);
case 'ENDS_WITH':
return mb_substr($label, -mb_strlen($match)) === (string) $match;

View File

@ -284,7 +284,7 @@ class Tables implements TablesInterface {
$entity_type_id = NULL;
// Relationship specifier can also contain the entity type ID, i.e.
// entity:node, entity:user or entity:taxonomy.
if (strpos($relationship_specifier, ':') !== FALSE) {
if (str_contains($relationship_specifier, ':')) {
[$relationship_specifier, $entity_type_id] = explode(':', $relationship_specifier, 2);
}
// Check for a valid relationship.

View File

@ -158,7 +158,7 @@ class DefaultHtmlRouteProvider implements EntityRouteProviderInterface, EntityHa
// @todo We have to check if a route contains a bundle in its path as
// test entities have inconsistent usage of "add-form" link templates.
// Fix it in https://www.drupal.org/node/2699959.
if (($bundle_key = $entity_type->getKey('bundle')) && strpos($route->getPath(), '{' . $expected_parameter . '}') !== FALSE) {
if (($bundle_key = $entity_type->getKey('bundle')) && str_contains($route->getPath(), '{' . $expected_parameter . '}')) {
$route->setDefault('_title_callback', EntityController::class . '::addBundleTitle');
// If the bundles are entities themselves, we can add parameter
// information to the route options.

View File

@ -85,7 +85,7 @@ class AjaxResponseSubscriber implements EventSubscriberInterface {
// @see Drupal.ajax.prototype.beforeSend()
$accept = $event->getRequest()->headers->get('accept', '');
if (strpos($accept, 'text/html') !== FALSE) {
if (str_contains($accept, 'text/html')) {
$response->headers->set('Content-Type', 'text/html; charset=utf-8');
// Browser IFRAMEs expect HTML. Browser extensions, such as Linkification

View File

@ -28,7 +28,7 @@ class RedirectLeadingSlashesSubscriber implements EventSubscriberInterface {
// submits back to the same URI this presents an open redirect
// vulnerability. Also, Drupal 7 renders the same page for
// http://www.example.org/foo and http://www.example.org////foo.
if (strpos($path, '//') !== FALSE) {
if (str_contains($path, '//')) {
$path = preg_replace('/\/+/', '/', $path);
$qs = $request->getQueryString();
if ($qs) {

View File

@ -123,7 +123,7 @@ class Dependency {
* @return static
*/
public static function createFromString($dependency) {
if (strpos($dependency, ':') !== FALSE) {
if (str_contains($dependency, ':')) {
[$project, $dependency] = explode(':', $dependency);
}
else {

View File

@ -60,7 +60,7 @@ class FormHelper {
$keys = array_keys($conditions);
$update_keys = FALSE;
foreach ($conditions as $id => $values) {
if (strpos($id, $search) !== FALSE) {
if (str_contains($id, $search)) {
$update_keys = TRUE;
$new_id = str_replace($search, $replace, $id);
// Replace the key and keep the array in the same order.

View File

@ -25,7 +25,7 @@ class LogMessageParser implements LogMessageParserInterface {
// Keys are not prefixed with anything according to PSR3 specs.
// If the message is "User {username} created" the variable key will be
// just "username".
if (strpos($message, '@' . $key) !== FALSE) {
if (str_contains($message, '@' . $key)) {
$key = '@' . $key;
}
}

View File

@ -54,9 +54,9 @@ class MailFormatHelper {
$text = str_replace("\r", '', $text);
// See if soft-wrapping is allowed.
$clean_indent = static::htmlToTextClean($indent);
$soft = strpos($clean_indent, ' ') === FALSE;
$soft = !str_contains($clean_indent, ' ');
// Check if the string has line breaks.
if (strpos($text, "\n") !== FALSE) {
if (str_contains($text, "\n")) {
// Remove trailing spaces to make existing breaks hard, but leave
// signature marker untouched (RFC 3676, Section 4.3).
$text = preg_replace('/(?(?<!^--) +\n| +\n)/m', "\n", $text);

View File

@ -169,7 +169,7 @@ class EntityConverter implements ParamConverterInterface {
public function applies($definition, $name, Route $route) {
if (!empty($definition['type']) && strpos($definition['type'], 'entity:') === 0) {
$entity_type_id = substr($definition['type'], strlen('entity:'));
if (strpos($definition['type'], '{') !== FALSE) {
if (str_contains($definition['type'], '{')) {
$entity_type_slug = substr($entity_type_id, 1, -1);
return $name != $entity_type_slug && in_array($entity_type_slug, $route->compile()->getVariables(), TRUE);
}

View File

@ -76,7 +76,7 @@ class EntityRevisionParamConverter implements ParamConverterInterface {
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
return isset($definition['type']) && strpos($definition['type'], 'entity_revision:') !== FALSE;
return isset($definition['type']) && str_contains($definition['type'], 'entity_revision:');
}
}

View File

@ -44,7 +44,7 @@ class EntityRevisionRouteEnhancer implements EnhancerInterface {
$options = $route->getOptions();
if (isset($options['parameters'])) {
foreach ($options['parameters'] as $name => $details) {
if (!empty($details['type']) && strpos($details['type'], 'entity_revision:') !== FALSE) {
if (!empty($details['type']) && str_contains($details['type'], 'entity_revision:')) {
$defaults['_entity_revision'] = $defaults[$name];
break;
}

View File

@ -27,7 +27,7 @@ class RequestHelper {
*/
public static function isCleanUrl(Request $request) {
$base_url = $request->getBaseUrl();
return (empty($base_url) || strpos($base_url, $request->getScriptName()) === FALSE);
return (empty($base_url) || !str_contains($base_url, $request->getScriptName()));
}
}

View File

@ -98,7 +98,7 @@ class RouteCompiler extends SymfonyRouteCompiler implements RouteCompilerInterfa
// patterns we need to check in the RouteProvider.
$fit = 0;
foreach ($parts as $k => $part) {
if (strpos($part, '{') === FALSE) {
if (!str_contains($part, '{')) {
$fit |= 1 << ($slashes - $k);
}
}

View File

@ -311,7 +311,7 @@ class UrlGenerator implements UrlGeneratorInterface {
$path = str_replace($this->decodedChars[0], $this->decodedChars[1], rawurlencode($path));
// Drupal paths rarely include dots, so skip this processing if possible.
if (strpos($path, '/.') !== FALSE) {
if (str_contains($path, '/.')) {
// the path segments "." and ".." are interpreted as relative reference when
// resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
// so we need to encode them as they are not used for this purpose here

View File

@ -55,7 +55,7 @@ trait DoTrustedCallbackTrait {
if (is_array($callback)) {
[$object_or_classname, $method_name] = $callback;
}
elseif (is_string($callback) && strpos($callback, '::') !== FALSE) {
elseif (is_string($callback) && str_contains($callback, '::')) {
[$object_or_classname, $method_name] = explode('::', $callback, 2);
}

View File

@ -89,7 +89,7 @@ trait AssertMailTrait {
// done. Any run of whitespace becomes a single space.
$normalized_mail = preg_replace('/\s+/', ' ', $mail[$field_name]);
$normalized_string = preg_replace('/\s+/', ' ', $string);
$string_found = (FALSE !== strpos($normalized_mail, $normalized_string));
$string_found = str_contains($normalized_mail, $normalized_string);
if ($string_found) {
break;
}

View File

@ -174,7 +174,7 @@ class TestDiscovery {
}
catch (MissingGroupException $e) {
// If the class name ends in Test and is not a migrate table dump.
if (preg_match('/Test$/', $classname) && strpos($classname, 'migrate_drupal\Tests\Table') === FALSE) {
if (preg_match('/Test$/', $classname) && !str_contains($classname, 'migrate_drupal\Tests\Table')) {
throw $e;
}
// If the class is @group annotation just skip it. Most likely it is an

View File

@ -149,7 +149,7 @@ class LinkGenerator implements LinkGeneratorInterface {
// Remove all HTML and PHP tags from a tooltip, calling expensive strip_tags()
// only when a quick strpos() gives suspicion tags are present.
if (isset($variables['options']['attributes']['title']) && strpos($variables['options']['attributes']['title'], '<') !== FALSE) {
if (isset($variables['options']['attributes']['title']) && str_contains($variables['options']['attributes']['title'], '<')) {
$variables['options']['attributes']['title'] = strip_tags($variables['options']['attributes']['title']);
}

View File

@ -178,7 +178,7 @@ class UnroutedUrlAssembler implements UnroutedUrlAssemblerInterface {
// is added, to allow simple string concatenation with other parts.
if (!empty($base_path_with_script)) {
$script_name = $request->getScriptName();
if (strpos($base_path_with_script, $script_name) !== FALSE) {
if (str_contains($base_path_with_script, $script_name)) {
$current_script_path = ltrim(substr($script_name, strlen($current_base_path)), '/') . '/';
}
}

View File

@ -53,7 +53,7 @@ use Drupal\Core\StringTranslation\TranslatableMarkup;
*/
function hook_link_alter(&$variables) {
// Add a warning to the end of route links to the admin section.
if (isset($variables['route_name']) && strpos($variables['route_name'], 'admin') !== FALSE) {
if (isset($variables['route_name']) && str_contains($variables['route_name'], 'admin')) {
$variables['text'] = new TranslatableMarkup('@text (Warning!)', ['@text' => $variables['text']]);
}
}

View File

@ -36,7 +36,7 @@ class BigPipeTestSubscriber implements EventSubscriberInterface {
$attachments = $response->getAttachments();
if (!isset($attachments['big_pipe_placeholders']) && !isset($attachments['big_pipe_nojs_placeholders'])) {
if (strpos($response->getContent(), static::CONTENT_TRIGGER_EXCEPTION) !== FALSE) {
if (str_contains($response->getContent(), static::CONTENT_TRIGGER_EXCEPTION)) {
throw new \Exception('Oh noes!');
}
}

View File

@ -40,7 +40,7 @@ class TestForm extends FormBase {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if (strpos($form_state->getValue('email'), '.com') === FALSE) {
if (!str_contains($form_state->getValue('email'), '.com')) {
$form_state->setErrorByName('email', $this->t('This is not a .com email address.'));
}
}

View File

@ -212,7 +212,7 @@ function ckeditor5_form_filter_format_form_alter(array &$form, FormStateInterfac
}
foreach ($plugins_config_form as $key => &$value) {
if (is_array($value) && strpos((string) $key, '#') === FALSE) {
if (is_array($value) && !str_contains((string) $key, '#')) {
_add_ajax_listeners_to_plugin_inputs($value);
}
}
@ -345,7 +345,7 @@ function _update_ckeditor5_html_filter(array $form, FormStateInterface $form_sta
if ($key === "#attached") {
$response->addAttachments(array_diff_key($value, ['placeholders' => '']));
}
elseif (is_array($value) && strpos((string) $key, '#') === FALSE) {
elseif (is_array($value) && !str_contains((string) $key, '#')) {
_add_attachments_to_editor_update_response($value, $response);
}
}

View File

@ -1040,7 +1040,7 @@ final class HTMLRestrictions {
private static function isWildcardAttributeName(string $attribute_name): bool {
// @see ::validateAllowedRestrictionsPhase3()
assert($attribute_name !== '*');
return strpos($attribute_name, '*') !== FALSE;
return str_contains($attribute_name, '*');
}
/**
@ -1315,7 +1315,7 @@ final class HTMLRestrictions {
// the attribute name contains a partial wildcard, more complex syntax
// is needed.
$to_allow['attributes'][] = [
'key' => strpos($name, '*') === FALSE ? $name : ['regexp' => ['pattern' => self::getRegExForWildCardAttributeName($name)]],
'key' => !str_contains($name, '*') ? $name : ['regexp' => ['pattern' => self::getRegExForWildCardAttributeName($name)]],
'value' => $allowed_attribute_value,
];
}

View File

@ -101,7 +101,7 @@ class SourceEditingPreventSelfXssConstraintValidator extends ConstraintValidator
*/
private static function isWildcardAttributeName(string $attribute_name): bool {
assert($attribute_name !== '*');
return strpos($attribute_name, '*') !== FALSE;
return str_contains($attribute_name, '*');
}
/**

View File

@ -571,7 +571,7 @@ final class SmartDefaultSettings {
foreach ($attributes_config as $attribute_name => $attribute_config) {
// 10^4 per surplus wildcard attribute.
if (strpos($attribute_name, '*') !== FALSE) {
if (str_contains($attribute_name, '*')) {
$surplus_score += pow(10, 4);
}
// 10^3 per surplus attribute.
@ -590,7 +590,7 @@ final class SmartDefaultSettings {
foreach ($attribute_config as $allowed_attribute_value => $allowed_attribute_value_config) {
// 10^1 per surplus wildcard attribute value.
if (strpos($allowed_attribute_value, '*') !== FALSE) {
if (str_contains($allowed_attribute_value, '*')) {
$surplus_score += pow(10, 1);
}
// 10^0 per surplus attribute value.

View File

@ -77,7 +77,7 @@ class UnpublishByKeywordComment extends ConfigurableActionBase implements Contai
$build = $this->viewBuilder->view($comment);
$text = $this->renderer->renderPlain($build);
foreach ($this->configuration['keywords'] as $keyword) {
if (strpos($text, $keyword) !== FALSE) {
if (str_contains($text, $keyword)) {
$comment->setUnpublished();
$comment->save();
break;

View File

@ -119,7 +119,7 @@ class ListElement implements ElementInterface {
}
else {
foreach (array_keys($group_build) as $title_key) {
if (isset($group_build[$title_key]['source']) && (strpos($title_key, 'title') !== FALSE || strpos($title_key, 'label') !== FALSE)) {
if (isset($group_build[$title_key]['source']) && (str_contains($title_key, 'title') || str_contains($title_key, 'label'))) {
$title = $group_build[$title_key]['source']['#markup'];
break;
}

View File

@ -462,7 +462,7 @@ class ModerationLocaleTest extends ModerationStateTestBase {
* A node object if a new one is being created, NULL otherwise.
*/
protected function submitNodeForm($title, $moderation_state, $default_translation = FALSE, $langcode = 'en') {
$is_new = strpos($this->getSession()->getCurrentUrl(), '/node/add/') !== FALSE;
$is_new = str_contains($this->getSession()->getCurrentUrl(), '/node/add/');
$edit = [
'title[0][value]' => $title,
'moderation_state[0][state]' => $moderation_state,

View File

@ -316,7 +316,7 @@ class EditorLoadingTest extends BrowserTestBase {
// Editor.module's JS settings present.
isset($settings['editor']),
// Editor.module's JS present.
strpos($this->getSession()->getPage()->getContent(), $this->getModulePath('editor') . '/js/editor.js') !== FALSE,
str_contains($this->getSession()->getPage()->getContent(), $this->getModulePath('editor') . '/js/editor.js'),
// Body field.
'//' . $type . '[@id="edit-' . $field_name . '-0-value"]',
];

View File

@ -337,7 +337,7 @@ class FieldStorageAddForm extends FormBase {
$widget_settings = $formatter_settings = [];
// Check if we're dealing with a preconfigured field.
if (strpos($field_storage_values['type'], 'field_ui:') !== FALSE) {
if (str_contains($field_storage_values['type'], 'field_ui:')) {
[, $field_type, $option_key] = explode(':', $field_storage_values['type'], 3);
$field_storage_values['type'] = $field_type;

View File

@ -56,7 +56,7 @@ class RouteSubscriber extends RouteSubscriberBase {
];
// If the entity type has no bundles and it doesn't use {bundle} in its
// admin path, use the entity type.
if (strpos($path, '{bundle}') === FALSE) {
if (!str_contains($path, '{bundle}')) {
$defaults['bundle'] = !$entity_type->hasKey('bundle') ? $entity_type_id : '';
}

View File

@ -82,7 +82,7 @@ function file_requirements($phase) {
elseif (preg_match("/Apache/i", $server_software)) {
$is_nginx = FALSE;
$is_apache = TRUE;
$fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE;
$fastcgi = str_contains($server_software, 'mod_fastcgi') || str_contains($server_software, 'mod_fcgi');
}
else {
$is_nginx = FALSE;

View File

@ -311,8 +311,7 @@ class HelpTopicsSyntaxTest extends BrowserTestBase {
// You can tell test modules because they are in package 'Testing', but
// test themes are only known by being found in test directories. So...
// exclude things in test directories.
if ((strpos($path, '/tests') === FALSE) &&
(strpos($path, '/testing') === FALSE)) {
if (!str_contains($path, '/tests') && !str_contains($path, '/testing')) {
$directories[$name] = $path . '/help_topics';
}
}

View File

@ -255,7 +255,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
$file_url = $file_url_generator->generateAbsoluteString($uri);
// Append the query string with the token, if necessary.
if ($token_query) {
$file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($token_query);
$file_url .= (str_contains($file_url, '?') ? '&' : '?') . UrlHelper::buildQuery($token_query);
}
return $file_url;

View File

@ -50,7 +50,7 @@ class PathProcessorImageStyles implements InboundPathProcessorInterface {
}
// Check if the string '/system/files/styles/' exists inside the path,
// that means we have a case of private file's image style.
elseif (strpos($path, '/system/files/styles/') !== FALSE) {
elseif (str_contains($path, '/system/files/styles/')) {
$path_prefix = '/system/files/styles/';
$path = substr($path, strpos($path, $path_prefix), strlen($path));
}

View File

@ -250,7 +250,7 @@ class ImageStylesPathAndUrlTest extends BrowserTestBase {
$this->assertSession()->statusCodeEquals(403);
// Verify that images are not appended to the response.
// Currently this test only uses PNG images.
if (strpos($generate_url, '.png') === FALSE) {
if (!str_contains($generate_url, '.png')) {
$this->fail('Confirming that private image styles are not appended require PNG file.');
}
else {

View File

@ -736,7 +736,7 @@ class FieldResolver {
* The property name from a path part.
*/
protected static function getPathPartPropertyName($part) {
return strpos($part, ':') !== FALSE ? explode(':', $part)[0] : $part;
return str_contains($part, ':') ? explode(':', $part)[0] : $part;
}
/**

View File

@ -101,7 +101,7 @@ class ResourceResponseValidator implements EventSubscriberInterface {
*/
public function onResponse(ResponseEvent $event) {
$response = $event->getResponse();
if (strpos($response->headers->get('Content-Type', ''), 'application/vnd.api+json') === FALSE) {
if (!str_contains($response->headers->get('Content-Type', ''), 'application/vnd.api+json')) {
return;
}

View File

@ -195,7 +195,7 @@ final class LinkCollection implements \IteratorAggregate {
* TRUE if the key is valid, FALSE otherwise.
*/
protected static function validKey($key) {
return is_string($key) && !is_numeric($key) && strpos($key, ':') === FALSE;
return is_string($key) && !is_numeric($key) && !str_contains($key, ':');
}
}

View File

@ -205,7 +205,7 @@ class FieldItemNormalizer extends NormalizerBase implements DenormalizerInterfac
$alternatives = [];
foreach ($keys as $key) {
$lev = levenshtein($search_key, $key);
if ($lev <= strlen($search_key) / 3 || strpos($key, $search_key) !== FALSE) {
if ($lev <= strlen($search_key) / 3 || str_contains($key, $search_key)) {
$alternatives[] = $key;
}
}

View File

@ -156,7 +156,7 @@ class NegotiationUrlForm extends ConfigFormBase {
]));
}
}
elseif (strpos($value, '/') !== FALSE) {
elseif (str_contains($value, '/')) {
// Throw a form error if the string contains a slash,
// which would not work.
$form_state->setErrorByName("prefix][$langcode", $this->t('The prefix may not contain a slash.'));

View File

@ -166,7 +166,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
// In case either the original base URL or the HTTP host contains a
// port, retain it.
if (isset($normalized_base_url) && strpos($normalized_base_url, ':') !== FALSE) {
if (isset($normalized_base_url) && str_contains($normalized_base_url, ':')) {
[, $port] = explode(':', $normalized_base_url);
$options['base_url'] .= ':' . $port;
}

View File

@ -138,7 +138,7 @@ class LanguageNegotiationInfoTest extends BrowserTestBase {
$last = $this->container->get('state')->get('language_test.language_negotiation_last');
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
$langcode = $last[$type];
$value = $type == LanguageInterface::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en';
$value = $type == LanguageInterface::TYPE_CONTENT || str_contains($type, 'test') ? 'it' : 'en';
$this->assertEquals($langcode, $value, new FormattableMarkup('The negotiated language for %type is %language', ['%type' => $type, '%language' => $value]));
}

View File

@ -137,7 +137,7 @@ class LanguageUrlRewritingTest extends BrowserTestBase {
// In case index.php is part of the URLs, we need to adapt the asserted
// URLs as well.
$index_php = strpos(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), 'index.php') !== FALSE;
$index_php = str_contains(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), 'index.php');
$request = Request::createFromGlobals();
$server = $request->server->all();

View File

@ -162,7 +162,7 @@ class DefaultsSectionStorage extends SectionStorageBase implements ContainerFact
$defaults['entity_type_id'] = $entity_type_id;
// If the entity type has no bundles and it doesn't use {bundle} in its
// admin path, use the entity type.
if (strpos($path, '{bundle}') === FALSE) {
if (!str_contains($path, '{bundle}')) {
if (!$entity_type->hasKey('bundle')) {
$defaults['bundle'] = $entity_type_id;
}
@ -265,7 +265,7 @@ class DefaultsSectionStorage extends SectionStorageBase implements ContainerFact
$defaults['bundle'] = $defaults[$defaults['bundle_key']];
}
if (is_string($value) && strpos($value, '.') !== FALSE) {
if (is_string($value) && str_contains($value, '.')) {
[$entity_type_id, $bundle, $view_mode] = explode('.', $value, 3);
}
elseif (!empty($defaults['entity_type_id']) && !empty($defaults['bundle']) && !empty($defaults['view_mode_name'])) {

View File

@ -194,7 +194,7 @@ class OverridesSectionStorage extends SectionStorageBase implements ContainerFac
* @see \Drupal\Core\ParamConverter\ParamConverterInterface::convert()
*/
private function extractEntityFromRoute($value, array $defaults) {
if (strpos($value, '.') !== FALSE) {
if (str_contains($value, '.')) {
[$entity_type_id, $entity_id] = explode('.', $value, 2);
}
elseif (isset($defaults['entity_type_id']) && !empty($defaults[$defaults['entity_type_id']])) {

View File

@ -153,7 +153,7 @@ class ContentPreviewToggleTest extends WebDriverTestBase {
// Filter will only return value if block contains expected text.
$blocks_with_expected_text = array_filter($blocks, function ($block, $key) use ($items) {
$block_text = $block->getText();
return strpos($block_text, $items[$key]) !== FALSE;
return str_contains($block_text, $items[$key]);
}, ARRAY_FILTER_USE_BOTH);
$this->assertSameSize($items, $blocks_with_expected_text);

View File

@ -178,7 +178,7 @@ class LocaleLookup extends CacheCollector {
}
}
if (is_string($value) && strpos($value, PoItem::DELIMITER) !== FALSE) {
if (is_string($value) && str_contains($value, PoItem::DELIMITER)) {
// Community translations imported from localize.drupal.org as well as
// migrated translations may contain @count[number].
$value = preg_replace('!@count\[\d+\]!', '@count', $value);

View File

@ -26,7 +26,7 @@ class MediaTestConstraintValidator extends ConstraintValidator {
return;
}
if (strpos($string_to_test, 'love Drupal') === FALSE) {
if (!str_contains($string_to_test, 'love Drupal')) {
$this->context->addViolation($constraint->message);
}
}

View File

@ -44,7 +44,7 @@ class MediaLibraryInceptionWidget extends MediaLibraryWidget {
$field_name = $element['#field_name'];
$entity = $form_state->getFormObject()->getEntity();
$input = $form_state->getUserInput();
if (!empty($input['_triggering_element_name']) && strpos($input['_triggering_element_name'], 'media-library-update') !== FALSE) {
if (!empty($input['_triggering_element_name']) && str_contains($input['_triggering_element_name'], 'media-library-update')) {
// This will validate a required field before an upload is completed.
$display = EntityFormDisplay::collectRenderDisplay($entity, 'edit');
$display->extractFormValues($entity, $form, $form_state);

View File

@ -115,7 +115,7 @@ class EntityContentBaseTest extends MigrateDrupal6TestBase {
// Match the expected message. Can't use default argument types, because
// we need to convert to string from TranslatableMarkup.
$argument = Argument::that(function ($msg) {
return strpos((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.')) !== FALSE;
return str_contains((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.'));
});
$message->display($argument, Argument::any())
->shouldBeCalled();

View File

@ -196,7 +196,7 @@ class Tasks extends InstallTasks {
// Ensure that the MySQL driver supports utf8mb4 encoding.
$version = Database::getConnection()->clientVersion();
if (FALSE !== strpos($version, 'mysqlnd')) {
if (str_contains($version, 'mysqlnd')) {
// The mysqlnd driver supports utf8mb4 starting at version 5.0.9.
$version = preg_replace('/^\D+([\d.]+).*/', '$1', $version);
if (version_compare($version, self::MYSQLND_MINIMUM_VERSION, '<')) {

View File

@ -27,7 +27,7 @@ class UnpublishByKeywordNode extends ConfigurableActionBase {
->view(clone $node);
$render = \Drupal::service('renderer')->render($elements);
foreach ($this->configuration['keywords'] as $keyword) {
if (strpos($render, $keyword) !== FALSE || strpos($node->label(), $keyword) !== FALSE) {
if (str_contains($render, $keyword) || str_contains($node->label(), $keyword)) {
$node->setUnpublished();
$node->save();
break;

View File

@ -51,7 +51,7 @@ class AliasPathProcessor implements InboundPathProcessorInterface, OutboundPathP
// also, to protect against this problem in arbitrary path processors,
// but it is duplicated here to protect any other URL generation code
// that might call this method separately.
if (strpos($path, '//') === 0) {
if (str_starts_with($path, '//')) {
$path = '/' . ltrim($path, '/');
}
}

View File

@ -132,10 +132,10 @@ class Connection extends DatabaseConnection implements SupportsTemporaryTablesIn
}
catch (\PDOException $e) {
if (static::getSQLState($e) == static::CONNECTION_FAILURE) {
if (strpos($e->getMessage(), 'password authentication failed for user') !== FALSE) {
if (str_contains($e->getMessage(), 'password authentication failed for user')) {
throw new DatabaseAccessDeniedException($e->getMessage(), $e->getCode(), $e);
}
elseif (strpos($e->getMessage(), 'database') !== FALSE && strpos($e->getMessage(), 'does not exist') !== FALSE) {
elseif (str_contains($e->getMessage(), 'database') && str_contains($e->getMessage(), 'does not exist')) {
throw new DatabaseNotFoundException($e->getMessage(), $e->getCode(), $e);
}
}

View File

@ -121,7 +121,7 @@ class Schema extends DatabaseSchema {
// Take into account that temporary tables are stored in a different schema.
// \Drupal\Core\Database\Connection::generateTemporaryTableName() sets the
// 'db_temporary_' prefix to all temporary tables.
if (strpos($key, '.') === FALSE && strpos($table, 'db_temporary_') === FALSE) {
if (!str_contains($key, '.') && !str_contains($table, 'db_temporary_')) {
$key = 'public.' . $key;
}
else {
@ -207,7 +207,7 @@ EOD;
*/
protected function resetTableInformation($table) {
$key = $this->connection->prefixTables('{' . $table . '}');
if (strpos($key, '.') === FALSE) {
if (!str_contains($key, '.')) {
$key = 'public.' . $key;
}
unset($this->tableInformation[$key]);
@ -564,7 +564,7 @@ EOD;
// exceed the 63 chars limit of PostgreSQL, we need to take care of that.
// cSpell:disable-next-line
// Example (drupal_Gk7Su_T1jcBHVuvSPeP22_I3Ni4GrVEgTYlIYnBJkro_idx).
if (strpos($index->indexname, 'drupal_') !== FALSE) {
if (str_contains($index->indexname, 'drupal_')) {
preg_match('/^drupal_(.*)_' . preg_quote($index_type) . '/', $index->indexname, $matches);
$index_name = $matches[1];
}

View File

@ -72,7 +72,7 @@ class Select extends QuerySelect {
}
// If there is a table alias specified, split it up.
if (strpos($field, '.') !== FALSE) {
if (str_contains($field, '.')) {
[$table, $table_field] = explode('.', $field);
}
// Figure out if the field has already been added.

View File

@ -333,7 +333,7 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
$text_processor = \Drupal::service('search.text_processor');
$simplified_key = trim($text_processor->analyze($key, $langcode));
$simplified_text = trim($text_processor->analyze($text, $langcode));
if ($simplified_key == '' || $simplified_text == '' || strpos($simplified_text, $simplified_key) === FALSE) {
if ($simplified_key == '' || $simplified_text == '' || !str_contains($simplified_text, $simplified_key)) {
// The simplified keyword and text do not match at all, or are empty.
return NULL;
}
@ -358,7 +358,7 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
// Since the split was done with preg_split(), the positions are byte counts
// not character counts, so use substr() not mb_substr() here.
$trial_text = trim($text_processor->analyze(substr($text, $start_pos, $proposed_end_pos - $start_pos), $langcode));
if (strpos($trial_text, $simplified_key) !== FALSE) {
if (str_contains($trial_text, $simplified_key)) {
// The proposed endpoint is fine, text still matches.
$max_end_index = $proposed_end_index;
}
@ -385,7 +385,7 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
// Since the split was done with preg_split(), the positions are byte counts
// not character counts, so use substr() not mb_substr() here.
$trial_text = trim($text_processor->analyze(substr($text, $proposed_start_pos, $end_pos - $proposed_start_pos), $langcode));
if (strpos($trial_text, $simplified_key) !== FALSE) {
if (str_contains($trial_text, $simplified_key)) {
// The proposed start point is fine, text still matches.
$min_start_index = $proposed_start_index;
}

View File

@ -521,7 +521,7 @@ class SearchQuery extends SelectExtender {
// search expression. So, use string replacement to change this to a
// calculated query expression, counting the number of occurrences so
// in the execute() method we can add arguments.
while (strpos($score, 'i.relevance') !== FALSE) {
while (str_contains($score, 'i.relevance')) {
$pieces = explode('i.relevance', $score, 2);
$score = implode('((ROUND(:normalization_' . $this->relevance_count . ', 4)) * i.score * t.count)', $pieces);
$this->relevance_count++;

View File

@ -231,7 +231,7 @@ final class LinksetController extends ControllerBase {
continue;
}
// Skip the attribute key if it has an asterisk (*).
if (strpos($key, '*') !== FALSE) {
if (str_contains($key, '*')) {
continue;
}
// Skip the value if it is an object.

View File

@ -215,7 +215,7 @@ function system_requirements($phase) {
];
// Tests clean URL support.
if ($phase == 'install' && $install_state['interactive'] && !$request_object->query->has('rewrite') && strpos($software, 'Apache') !== FALSE) {
if ($phase == 'install' && $install_state['interactive'] && !$request_object->query->has('rewrite') && str_contains($software, 'Apache')) {
// If the Apache rewrite module is not enabled, Apache version must be >=
// 2.2.16 because of the FallbackResource directive in the root .htaccess
// file. Since the Apache version reported by the server is dependent on the
@ -705,7 +705,7 @@ function system_requirements($phase) {
$htaccess_file = $protected_dir->getPath() . '/.htaccess';
// Check for the string which was added to the recommended .htaccess file
// in the latest security update.
if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || !str_contains($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003')) {
$url = 'https://www.drupal.org/SA-CORE-2013-003';
$requirements[$htaccess_file] = [
'title' => new TranslatableMarkup($protected_dir->getTitle()),
@ -1360,7 +1360,7 @@ function system_requirements($phase) {
$provider = $connection->getProvider();
if ($provider !== 'core' && !\Drupal::moduleHandler()->moduleExists($provider)) {
$autoload = $connection->getConnectionOptions()['autoload'] ?? '';
if (strpos($autoload, 'src/Driver/Database/') !== FALSE) {
if (str_contains($autoload, 'src/Driver/Database/')) {
$post_update_registry = \Drupal::service('update.post_update_registry');
$pending_updates = $post_update_registry->getPendingUpdateInformation();
if (!in_array('enable_provider_database_driver', array_keys($pending_updates['system']['pending'] ?? []), TRUE)) {

View File

@ -18,7 +18,7 @@ class AdvisoryTestClientMiddleware {
return function ($handler) {
return function (RequestInterface $request, array $options) use ($handler): PromiseInterface {
$test_end_point = \Drupal::state()->get('advisories_test_endpoint');
if ($test_end_point && strpos($request->getUri(), '://updates.drupal.org/psa.json') !== FALSE) {
if ($test_end_point && str_contains($request->getUri(), '://updates.drupal.org/psa.json')) {
// Only override $uri if it matches the advisories JSON feed to avoid
// changing any other uses of the 'http_client' service during tests with
// this module installed.

View File

@ -43,13 +43,13 @@ class FormTestClickedButtonForm extends FormBase {
foreach ($args as $arg) {
$name = 'button' . ++$i;
// 's', 'b', or 'i' in the argument define the button type wanted.
if (strpos($arg, 's') !== FALSE) {
if (str_contains($arg, 's')) {
$type = 'submit';
}
elseif (strpos($arg, 'b') !== FALSE) {
elseif (str_contains($arg, 'b')) {
$type = 'button';
}
elseif (strpos($arg, 'i') !== FALSE) {
elseif (str_contains($arg, 'i')) {
$type = 'image_button';
}
else {
@ -69,7 +69,7 @@ class FormTestClickedButtonForm extends FormBase {
}
// 'r' for restricted, so we can test that button click detection code
// correctly takes #access security into account.
if (strpos($arg, 'r') !== FALSE) {
if (str_contains($arg, 'r')) {
$form[$name]['#access'] = FALSE;
}
}

View File

@ -126,7 +126,7 @@ class FormTestMachineNameValidationForm extends FormBase {
* @return bool
*/
public function load($machine_name) {
if (strpos($machine_name, 'duplicate') !== FALSE) {
if (str_contains($machine_name, 'duplicate')) {
return TRUE;
}

View File

@ -21,7 +21,7 @@ class JqueryUiTestAssetsController extends ControllerBase {
public function build($library) {
// If there are pipes in $library, they are separating multiple library
// names.
if (strpos($library, '|') !== FALSE) {
if (str_contains($library, '|')) {
$library = explode('|', $library);
$library = array_map(function ($item) {
return "core/$item";

View File

@ -53,7 +53,7 @@ class CheckboxTest extends BrowserTestBase {
elseif ($return_value === '1foobar') {
$checked = ($default_value === '1foobar');
}
$checked_in_html = strpos($form, 'checked') !== FALSE;
$checked_in_html = str_contains($form, 'checked');
$message = new FormattableMarkup('#default_value is %default_value #return_value is %return_value.', ['%default_value' => var_export($default_value, TRUE), '%return_value' => var_export($return_value, TRUE)]);
$this->assertSame($checked, $checked_in_html, $message);
}

Some files were not shown because too many files have changed in this diff Show More