Commit d21dcb2b authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Benni Mack
Browse files

[TASK] Use str_contains instead of strpos where possible

The (ugly) statement strpos($haystack, 'needle') !== false can be safely
replaced with str_contains($haystack, 'needle'). This is possible, as
a symfony polyfill for php 8.0 functions is in place.

Resolves: #95466
Releases: master
Change-Id: I313f47832a254c23c6815b6b44557a01019e59e7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71429

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 679ca065
......@@ -649,7 +649,7 @@ class ShortcutRepository
default:
$iconIdentifier = '';
if (strpos($moduleName, '_') !== false) {
if (str_contains($moduleName, '_')) {
[$mainModule, $subModule] = explode('_', $moduleName, 2);
$iconIdentifier = $this->moduleLoader->modules[$mainModule]['sub'][$subModule]['iconIdentifier'] ?? '';
} elseif ($moduleName !== '') {
......
......@@ -49,7 +49,7 @@ class BackendUserConfiguration
*/
public function get(string $key)
{
return (strpos($key, '.') !== false) ? $this->getFromDottedNotation($key) : $this->backendUser->uc[$key];
return (str_contains($key, '.')) ? $this->getFromDottedNotation($key) : $this->backendUser->uc[$key];
}
/**
......@@ -70,7 +70,7 @@ class BackendUserConfiguration
*/
public function set(string $key, $value): void
{
if (strpos($key, '.') !== false) {
if (str_contains($key, '.')) {
$this->setFromDottedNotation($key, $value);
} else {
$this->backendUser->uc[$key] = $value;
......
......@@ -252,7 +252,7 @@ class BackendController
$logoHeight = $imageInfo->getHeight() ?? '22';
// High-resolution?
if (strpos($logoPath, '@2x.') !== false) {
if (str_contains($logoPath, '@2x.')) {
$logoWidth /= 2;
$logoHeight /= 2;
}
......@@ -390,7 +390,7 @@ class BackendController
// check if the start module has additional parameters, so a redirect to a specific
// action is possible
if (strpos($startModule, '->') !== false) {
if (str_contains($startModule, '->')) {
[$startModule, $startModuleParameters] = explode('->', $startModule, 2);
// if no GET parameters are set, check if there are parameters given from the UC
if (!$moduleParameters && $startModuleParameters) {
......
......@@ -644,7 +644,7 @@ class NewRecordController
$doktype = (int)$page['doktype'];
$allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'] ?? $GLOBALS['PAGES_TYPES']['default']['allowedTables'] ?? '';
// If all tables or the table is listed as an allowed type, return TRUE
return $rootLevelConstraintMatches && (strpos($allowedTableList, '*') !== false || GeneralUtility::inList($allowedTableList, $table));
return $rootLevelConstraintMatches && (str_contains($allowedTableList, '*') || GeneralUtility::inList($allowedTableList, $table));
}
/**
......
......@@ -108,9 +108,9 @@ class SingleFieldContainer extends AbstractContainer
}
$processedTcaType = $this->data['processedTca']['ctrl']['type'] ?? '';
$typeField = strpos($processedTcaType, ':') === false
$typeField = !str_contains($processedTcaType, ':')
? $processedTcaType
: substr($processedTcaType, 0, strpos($processedTcaType, ':'));
: substr($processedTcaType, 0, (int)strpos($processedTcaType, ':'));
// JavaScript code for event handlers:
$parameterArray['fieldChangeFunc'] = [];
......
......@@ -745,7 +745,7 @@ abstract class AbstractItemProvider
$foreignTableClause = $result['processedTca']['columns'][$localFieldName]['config']['foreign_table_where'];
}
// Replace possible markers in query
if (strpos($foreignTableClause, '###REC_FIELD_') !== false) {
if (str_contains($foreignTableClause, '###REC_FIELD_')) {
// " AND table.field='###REC_FIELD_field1###' AND ..." -> array(" AND table.field='", "field1###' AND ...")
$whereClauseParts = explode('###REC_FIELD_', $foreignTableClause);
foreach ($whereClauseParts as $key => $value) {
......@@ -771,7 +771,7 @@ abstract class AbstractItemProvider
}
$foreignTableClause = implode('', $whereClauseParts);
}
if (strpos($foreignTableClause, '###CURRENT_PID###') !== false) {
if (str_contains($foreignTableClause, '###CURRENT_PID###')) {
// Use pid from parent page clause if in flex form context
if (!empty($result['flexParentDatabaseRow']['pid'])) {
$effectivePid = $result['flexParentDatabaseRow']['pid'];
......
......@@ -56,7 +56,7 @@ class DatabaseRecordTypeValue implements FormDataProviderInterface
if (!empty($result['processedTca']['ctrl']['type'])) {
$tcaTypeField = $result['processedTca']['ctrl']['type'];
if (strpos($tcaTypeField, ':') === false) {
if (!str_contains($tcaTypeField, ':')) {
// $tcaTypeField is the name of a field in database row
if (!array_key_exists($tcaTypeField, $result['databaseRow'])) {
throw new \UnexpectedValueException(
......
......@@ -275,7 +275,7 @@ class TcaFlexProcess implements FormDataProviderInterface
$excludeFieldsPrefix = $result['tableName'] . ':' . $fieldName . ';' . $flexIdentifier . ';';
$nonExcludeFields = [];
foreach ($userNonExcludeFields as $userNonExcludeField) {
if (strpos($userNonExcludeField, $excludeFieldsPrefix) !== false) {
if (str_contains($userNonExcludeField, $excludeFieldsPrefix)) {
$exploded = explode(';', $userNonExcludeField);
$sheetName = $exploded[2];
$allowedFlexFieldName = $exploded[3];
......
......@@ -83,7 +83,7 @@ class InlineStackProcessor
}
// Extract FlexForm from field part (if any)
if (strpos($unstable['field'], ':') !== false) {
if (str_contains($unstable['field'], ':')) {
$fieldParts = GeneralUtility::trimExplode(':', $unstable['field']);
$unstable['field'] = array_shift($fieldParts);
// FlexForm parts start with data:
......
......@@ -62,7 +62,7 @@ class Application extends AbstractApplication
// Add applicationType attribute to request: This is backend and maybe backend ajax.
$applicationType = SystemEnvironmentBuilder::REQUESTTYPE_BE;
if (strpos($request->getUri()->getPath(), '/typo3/ajax/') !== false || strpos($request->getQueryParams()['route'] ?? '', '/ajax/') === 0) {
if (str_contains($request->getUri()->getPath(), '/typo3/ajax/') || strpos($request->getQueryParams()['route'] ?? '', '/ajax/') === 0) {
$applicationType |= SystemEnvironmentBuilder::REQUESTTYPE_AJAX;
}
$request = $request->withAttribute('applicationType', $applicationType);
......
......@@ -56,7 +56,7 @@ class LockedBackendGuard implements MiddlewareInterface
} catch (BackendLockedException $e) {
// Looks like an AJAX request that can handle JSON, (usually from the timeout functionality)
// So, let's form a request that fits
if (strpos($request->getHeaderLine('Accept'), 'application/json') !== false) {
if (str_contains($request->getHeaderLine('Accept'), 'application/json')) {
$session = [
'timed_out' => false,
'will_time_out' => false,
......
......@@ -182,7 +182,7 @@ class ModuleLoader
// Check if this is a submodule
$mainModule = '';
if (strpos($name, '_') !== false) {
if (str_contains($name, '_')) {
[$mainModule, ] = explode('_', $name, 2);
}
......@@ -254,19 +254,19 @@ class ModuleLoader
}
$access = strtolower($MCONF['access']);
// Check if this module is only allowed by system maintainers (= admins who are in the list of system maintainers)
if (strpos($MCONF['access'], BackendUserAuthentication::ROLE_SYSTEMMAINTAINER) !== false) {
if (str_contains($MCONF['access'], BackendUserAuthentication::ROLE_SYSTEMMAINTAINER)) {
return $this->BE_USER->isSystemMaintainer();
}
// Checking if admin-access is required
// If admin-permissions is required then return TRUE if user is admin
if (strpos($access, 'admin') !== false && $this->BE_USER->isAdmin()) {
if (str_contains($access, 'admin') && $this->BE_USER->isAdmin()) {
return true;
}
// This will add modules to the select-lists of user and groups
if (strpos($access, 'user') !== false) {
if (str_contains($access, 'user')) {
$this->modListUser[] = $name;
}
if (strpos($access, 'group') !== false) {
if (str_contains($access, 'group')) {
$this->modListGroup[] = $name;
}
// This checks if a user is permitted to access the module
......
......@@ -360,7 +360,7 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger
$table = 'pages';
$field = 'pages';
// get categories instead of pages
if (strpos($record['CType'], 'menu_categorized') !== false) {
if (str_contains($record['CType'], 'menu_categorized')) {
$table = 'sys_category';
$field = 'selected_categories';
}
......
......@@ -319,7 +319,7 @@ class ShortcutButton implements ButtonInterface, PositionInterface
$arguments = $this->arguments;
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if (strpos($routeIdentifier, '/') !== false) {
if (str_contains($routeIdentifier, '/')) {
trigger_error('Automatic fallback for the route path is deprecated and will be removed in v12.', E_USER_DEPRECATED);
$routeIdentifier = $this->getRouteIdentifierByRoutePath($routeIdentifier);
}
......
......@@ -49,7 +49,7 @@ class FileStorageTreeProvider
} catch (FolderDoesNotExistException | InsufficientFolderAccessPermissionsException $e) {
$parentFolder = null;
}
if (strpos($folder->getRole(), FolderInterface::ROLE_MOUNT) !== false) {
if (str_contains($folder->getRole(), FolderInterface::ROLE_MOUNT)) {
$tableName = 'sys_filemount';
$isStorage = true;
} elseif ($parentFolder === null || $folder->getIdentifier() === $storage->getRootLevelFolder(true)->getIdentifier()) {
......
......@@ -192,7 +192,7 @@ abstract class AbstractTreeView
*/
protected function getThisScript()
{
return strpos($this->thisScript, '?') === false ? $this->thisScript . '?' : $this->thisScript . '&';
return !str_contains($this->thisScript, '?') ? $this->thisScript . '?' : $this->thisScript . '&';
}
/**
......
......@@ -634,7 +634,7 @@ class BackendUtility
$typeNum = 0;
if ($GLOBALS['TCA'][$table] ?? false) {
$field = $GLOBALS['TCA'][$table]['ctrl']['type'] ?? '';
if (strpos($field, ':') !== false) {
if (str_contains($field, ':')) {
[$pointerField, $foreignTableTypeField] = explode(':', $field);
// Get field value from database if field is not in the $row array
if (!isset($row[$pointerField])) {
......
......@@ -107,7 +107,7 @@ class BackendLayout
*/
public function setIdentifier($identifier)
{
if (strpos($identifier, '__') !== false) {
if (str_contains($identifier, '__')) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597630
......
......@@ -52,7 +52,7 @@ class BackendLayoutCollection
*/
public function setIdentifier($identifier)
{
if (strpos($identifier, '__') !== false) {
if (str_contains($identifier, '__')) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597631
......@@ -72,7 +72,7 @@ class BackendLayoutCollection
{
$identifier = $backendLayout->getIdentifier();
if (strpos($identifier, '__') !== false) {
if (str_contains($identifier, '__')) {
throw new \UnexpectedValueException(
'BackendLayout Identifier "' . $identifier . '" must not contain "__"',
1381597628
......
......@@ -43,7 +43,7 @@ class DataProviderCollection implements SingletonInterface
*/
public function add($identifier, $classNameOrObject)
{
if (strpos($identifier, '__') !== false) {
if (str_contains($identifier, '__')) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597629
......@@ -103,7 +103,7 @@ class DataProviderCollection implements SingletonInterface
{
$backendLayout = null;
if (strpos($combinedIdentifier, '__') === false) {
if (!str_contains($combinedIdentifier, '__')) {
$dataProviderIdentifier = 'default';
$backendLayoutIdentifier = $combinedIdentifier;
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment