Modernize to PHP 8.1

This commit is contained in:
Yassine Guedidi
2025-04-05 14:01:48 +02:00
parent ca018c77e3
commit 9e2720cddc
26 changed files with 48 additions and 52 deletions

View File

@ -100,8 +100,8 @@ class CleanDuplicatesCommand extends Command
private function similarUrl($url)
{
if (\in_array(substr($url, -1), ['/', '#'], true)) { // get rid of "/" and "#" and the end of urls
return substr($url, 0, \strlen($url));
if (\in_array(substr((string) $url, -1), ['/', '#'], true)) { // get rid of "/" and "#" and the end of urls
return substr((string) $url, 0, \strlen((string) $url));
}
return $url;

View File

@ -144,7 +144,7 @@ class InstallCommand extends Command
// return version should be like "PostgreSQL 9.5.4 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.38), 64-bit"
$version = $conn->executeQuery('SELECT version();')->fetchOne();
preg_match('/PostgreSQL ([0-9\.]+)/i', $version, $matches);
preg_match('/PostgreSQL ([0-9\.]+)/i', (string) $version, $matches);
if (isset($matches[1]) & version_compare($matches[1], '9.2.0', '<')) {
$fulfilled = false;

View File

@ -350,7 +350,7 @@ class ConfigController extends AbstractController
$backupCodes = (new BackupCodes())->toArray();
$backupCodesHashed = array_map(
fn ($backupCode) => password_hash($backupCode, \PASSWORD_DEFAULT),
fn ($backupCode) => password_hash((string) $backupCode, \PASSWORD_DEFAULT),
$backupCodes
);

View File

@ -67,7 +67,7 @@ class EntryController extends AbstractController
$action = 'tag';
if (isset($values['tags'])) {
$labels = array_filter(explode(',', $values['tags']),
$labels = array_filter(explode(',', (string) $values['tags']),
function ($v) {
$v = trim($v);
@ -616,7 +616,7 @@ class EntryController extends AbstractController
*/
private function showEntries($type, Request $request, $page)
{
$searchTerm = (isset($request->query->all('search_entry')['term']) ? trim($request->query->all('search_entry')['term']) : '');
$searchTerm = (isset($request->query->all('search_entry')['term']) ? trim((string) $request->query->all('search_entry')['term']) : '');
$currentRoute = $request->query->get('currentRoute') ?? '';
$currentEntryId = $request->attributes->getInt('id');

View File

@ -45,10 +45,10 @@ class TagController extends AbstractController
$form->handleRequest($request);
$tags = $form->get('label')->getData() ?? '';
$tagsExploded = explode(',', $tags);
$tagsExploded = explode(',', (string) $tags);
// avoid too much tag to be added
if (\count($tagsExploded) >= NewTagType::MAX_TAGS || \strlen($tags) >= NewTagType::MAX_LENGTH) {
if (\count($tagsExploded) >= NewTagType::MAX_TAGS || \strlen((string) $tags) >= NewTagType::MAX_LENGTH) {
$message = $translator->trans('flashes.tag.notice.too_much_tags', [
'%tags%' => NewTagType::MAX_TAGS,
'%characters%' => NewTagType::MAX_LENGTH,
@ -250,7 +250,7 @@ class TagController extends AbstractController
// check to avoid duplicate tags creation
foreach ($this->entityManager->getUnitOfWork()->getScheduledEntityInsertions() as $entity) {
if ($entity instanceof Tag && strtolower($entity->getLabel()) === strtolower($filter)) {
if ($entity instanceof Tag && strtolower($entity->getLabel()) === strtolower((string) $filter)) {
continue 2;
}
$this->entityManager->persist($entry);

View File

@ -22,7 +22,7 @@ class JsonArrayType extends JsonType
$value = \is_resource($value) ? stream_get_contents($value) : $value;
return json_decode($value, true);
return json_decode((string) $value, true);
}
public function getName(): string

View File

@ -383,7 +383,7 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
foreach ($this->backupCodes as $key => $backupCode) {
// backup code are hashed using `password_hash`
// see ConfigController->otpAppAction
if (password_verify($code, $backupCode)) {
if (password_verify($code, (string) $backupCode)) {
return $key;
}
}

View File

@ -25,7 +25,7 @@ class DownloadImages
$wallabagUrl,
private readonly LoggerInterface $logger,
) {
$this->wallabagUrl = rtrim($wallabagUrl, '/');
$this->wallabagUrl = rtrim((string) $wallabagUrl, '/');
$this->mimeTypes = new MimeTypes();
$this->setFolder();
@ -291,7 +291,7 @@ class DownloadImages
preg_match_all($pattern, $srcsetAttribute, $matches);
$srcset = \call_user_func_array('array_merge', $matches);
$srcsetUrls = array_map(fn ($src) => trim(explode(' ', $src, 2)[0]), $srcset);
$srcsetUrls = array_map(fn ($src) => trim(explode(' ', (string) $src, 2)[0]), $srcset);
$urls = array_merge($srcsetUrls, $urls);
}

View File

@ -39,7 +39,7 @@ class TagsAssigner
}
foreach ($tags as $label) {
$label = trim(mb_convert_case($label, \MB_CASE_LOWER));
$label = trim(mb_convert_case((string) $label, \MB_CASE_LOWER));
// avoid empty tag
if ('' === $label) {

View File

@ -39,7 +39,7 @@ class ChromeImport extends BrowserImport
'is_archived' => (int) $this->markAsRead,
'is_starred' => false,
'tags' => '',
'created_at' => substr($entry['date_added'], 0, 10),
'created_at' => substr((string) $entry['date_added'], 0, 10),
];
if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) {

View File

@ -39,7 +39,7 @@ class FirefoxImport extends BrowserImport
'is_archived' => (int) $this->markAsRead,
'is_starred' => false,
'tags' => '',
'created_at' => substr($entry['dateAdded'], 0, 10),
'created_at' => substr((string) $entry['dateAdded'], 0, 10),
];
if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) {

View File

@ -95,7 +95,7 @@ class PinboardImport extends AbstractImport
'is_archived' => ('no' === $importedEntry['toread']) || $this->markAsRead,
'is_starred' => false,
'created_at' => $importedEntry['time'],
'tags' => explode(' ', $importedEntry['tags']),
'tags' => explode(' ', (string) $importedEntry['tags']),
];
$entry = new Entry($this->user);

View File

@ -20,6 +20,6 @@ class Matches
return false;
}
return false !== stripos($subject, (string) $pattern);
return false !== stripos((string) $subject, (string) $pattern);
}
}

View File

@ -20,6 +20,6 @@ class NotMatches
return true;
}
return false === stripos($subject, (string) $pattern);
return false === stripos((string) $subject, (string) $pattern);
}
}

View File

@ -16,7 +16,7 @@ class PatternMatches
{
public function __invoke($subject, $pattern)
{
$count = preg_match("`$pattern`i", $subject);
$count = preg_match("`$pattern`i", (string) $subject);
return \is_int($count) && $count > 0;
}

View File

@ -95,11 +95,11 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
$extraFields = [];
foreach ($extraFieldsStrings as $extraField) {
if (!str_contains($extraField, '=')) {
if (!str_contains((string) $extraField, '=')) {
continue;
}
[$fieldName, $fieldValue] = explode('=', $extraField, 2);
[$fieldName, $fieldValue] = explode('=', (string) $extraField, 2);
$extraFields[$fieldName] = $fieldValue;
}

View File

@ -98,9 +98,9 @@ class LoginFormAuthenticator
$extraFields = [];
foreach ($siteConfig->getExtraFields() as $fieldName => $fieldValue) {
if (str_starts_with($fieldValue, '@=')) {
if (str_starts_with((string) $fieldValue, '@=')) {
$fieldValue = $this->expressionLanguage->evaluate(
substr($fieldValue, 2),
substr((string) $fieldValue, 2),
[
'config' => $siteConfig,
]

View File

@ -34,20 +34,20 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface
public function getFilters(): array
{
return [
new TwigFilter('removeWww', [$this, 'removeWww']),
new TwigFilter('removeScheme', [$this, 'removeScheme']),
new TwigFilter('removeSchemeAndWww', [$this, 'removeSchemeAndWww']),
new TwigFilter('removeWww', $this->removeWww(...)),
new TwigFilter('removeScheme', $this->removeScheme(...)),
new TwigFilter('removeSchemeAndWww', $this->removeSchemeAndWww(...)),
];
}
public function getFunctions(): array
{
return [
new TwigFunction('count_entries', [$this, 'countEntries']),
new TwigFunction('count_tags', [$this, 'countTags']),
new TwigFunction('display_stats', [$this, 'displayStats']),
new TwigFunction('asset_file_exists', [$this, 'assetFileExists']),
new TwigFunction('theme_class', [$this, 'themeClass']),
new TwigFunction('count_entries', $this->countEntries(...)),
new TwigFunction('count_tags', $this->countTags(...)),
new TwigFunction('display_stats', $this->displayStats(...)),
new TwigFunction('asset_file_exists', $this->assetFileExists(...)),
new TwigFunction('theme_class', $this->themeClass(...)),
];
}