Use str_contains and similar instead of strpos

This commit is contained in:
Jan Böhmer 2023-05-27 23:58:28 +02:00
parent 508de10191
commit 1dbf36b86b
16 changed files with 18 additions and 19 deletions

View file

@ -134,7 +134,7 @@ class AttachmentPathResolver
$count = 0;
//When path is a footprint we have to first run the string through our lecagy german mapping functions
if (strpos($placeholder_path, '%FOOTPRINTS%') !== false) {
if (str_contains($placeholder_path, '%FOOTPRINTS%')) {
$placeholder_path = $this->convertOldFootprintPath($placeholder_path);
}
@ -151,7 +151,7 @@ class AttachmentPathResolver
}
//Path is invalid if path is directory traversal
if (false !== strpos($placeholder_path, '..')) {
if (str_contains($placeholder_path, '..')) {
return null;
}

View file

@ -78,7 +78,7 @@ class AttachmentURLGenerator
}
//Our absolute path must begin with public path, or we can not use it for asset pathes.
if (0 !== strpos($absolute_path, $public_path)) {
if (!str_starts_with($absolute_path, $public_path)) {
return null;
}

View file

@ -108,7 +108,7 @@ class FileTypeFilterTools
}
//Convert *.jpg to .jpg
if (0 === strpos($element, '*.')) {
if (str_starts_with($element, '*.')) {
$element = str_replace('*.', '.', $element);
}
@ -119,7 +119,7 @@ class FileTypeFilterTools
$element = 'video/*';
} elseif ('audio' === $element || 'audio/' === $element) {
$element = 'audio/*';
} elseif (!preg_match('#^[-\w.]+/[-\w.*]+#', $element) && 0 !== strpos($element, '.')) {
} elseif (!preg_match('#^[-\w.]+/[-\w.*]+#', $element) && !str_starts_with($element, '.')) {
//Convert jpg to .jpg
$element = '.'.$element;
}
@ -147,7 +147,7 @@ class FileTypeFilterTools
foreach ($elements as $element) {
$element = trim($element);
if (0 === strpos($element, '.')) {
if (str_starts_with($element, '.')) {
//We found an explicit specified file extension -> add it to list
$extensions[] = substr($element, 1);
} elseif ('image/*' === $element) {

View file

@ -79,7 +79,7 @@ final class BarcodeGenerator
$repr = 'data:';
$repr .= $mime;
if (0 === strpos($mime, 'text/')) {
if (str_starts_with($mime, 'text/')) {
$repr .= ','.rawurlencode($data);
} else {
$repr .= ';base64,'.base64_encode($data);

View file

@ -130,7 +130,7 @@ class TreeViewGenerator
}
//Translate text if text starts with $$
if (0 === strpos($item->getText(), '$$')) {
if (str_starts_with($item->getText(), '$$')) {
$item->setText($this->translator->trans(substr($item->getText(), 2)));
}
}

View file

@ -215,7 +215,7 @@ class PermissionManager
//Set every op listed in also Set
foreach ($op['alsoSet'] as $set_also) {
//If the alsoSet value contains a dot then we set the operation of another permission
if (false !== strpos($set_also, '.')) {
if (str_contains($set_also, '.')) {
[$set_perm, $set_op] = explode('.', $set_also);
} else {
//Else we set the operation of the same permission