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

@ -1,4 +1,2 @@
framework:
test: true
session:
storage_id: session.storage.mock_file

View file

@ -9,6 +9,7 @@
>
<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="App\Kernel"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>

View file

@ -62,7 +62,7 @@ class RedirectController extends AbstractController
//If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string
if (($this->enforce_index_php || !$this->checkIfModRewriteAvailable())
&& false === strpos($new_url, 'index.php')) {
&& !str_contains($new_url, 'index.php')) {
//Like Request::getUriForPath only with index.php
$new_url = $request->getSchemeAndHttpHost().$request->getBaseUrl().'/index.php/'.$locale.$request->getPathInfo();
}

View file

@ -198,7 +198,7 @@ class SelectAPIController extends AbstractController
//Remove the data-* prefix for each key
$data = array_combine(
array_map(static function ($key) {
if (strpos($key, 'data-') === 0) {
if (str_starts_with($key, 'data-')) {
return substr($key, 5);
}
return $key;

View file

@ -417,7 +417,7 @@ abstract class Attachment extends AbstractNamedDBElement
{
//Only set if the URL is not empty
if (!empty($url)) {
if (false !== strpos($url, '%BASE%') || false !== strpos($url, '%MEDIA%')) {
if (str_contains($url, '%BASE%') || str_contains($url, '%MEDIA%')) {
throw new InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
}

View file

@ -222,7 +222,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
*/
public function isCLIEntry(): bool
{
return strpos($this->username, '!!!CLI ') === 0;
return str_starts_with($this->username, '!!!CLI ');
}
/**

View file

@ -128,7 +128,7 @@ final class PermissionData implements \JsonSerializable
public function isPermissionSet(string $permission, string $operation): bool
{
//We cannot access metadata via normal permission data
if (strpos($permission, '$') !== false) {
if (str_contains($permission, '$')) {
return false;
}

View file

@ -96,7 +96,7 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface
/* Dont redirect tree endpoints, as this would cause trouble and creates multiple flash
warnigs for one page reload */
if (false !== strpos($request->getUri(), '/tree/')) {
if (str_contains($request->getUri(), '/tree/')) {
return;
}

View file

@ -138,7 +138,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface
//Check if we need to make this thing small
if (isset($options['attr']['class'])) {
$view->vars['sm'] = false !== strpos($options['attr']['class'], 'form-control-sm');
$view->vars['sm'] = str_contains($options['attr']['class'], 'form-control-sm');
}
$view->vars['unit'] = $options['unit'];

View file

@ -110,7 +110,7 @@ class LabelResponse extends Response
*/
public function setContentDisposition(string $disposition, string $filename, string $filenameFallback = ''): self
{
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) {
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || str_contains($filename, '%'))) {
$encoding = mb_detect_encoding($filename, null, true) ?: '8bit';
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {

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