1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-07-02 16:38:38 +00:00

Modernize to PHP 7.4

This commit is contained in:
Yassine Guedidi 2025-04-05 13:20:44 +02:00
parent ce8ed589d5
commit 4168727f36
21 changed files with 31 additions and 75 deletions

View file

@ -14,5 +14,5 @@ return RectorConfig::configure()
]) ])
->withImportNames(importShortClasses: false) ->withImportNames(importShortClasses: false)
->withAttributesSets(doctrine: true) ->withAttributesSets(doctrine: true)
->withPhpSets(php73: true) ->withPhpSets(php74: true)
->withTypeCoverageLevel(0); ->withTypeCoverageLevel(0);

View file

@ -107,9 +107,7 @@ class ImportCommand extends Command
// Turning off doctrine default logs queries for saving memory // Turning off doctrine default logs queries for saving memory
$middlewares = $this->entityManager->getConnection()->getConfiguration()->getMiddlewares(); $middlewares = $this->entityManager->getConnection()->getConfiguration()->getMiddlewares();
$middlewaresWithoutLogging = array_filter($middlewares, function (Middleware $middleware) { $middlewaresWithoutLogging = array_filter($middlewares, fn (Middleware $middleware) => !$middleware instanceof LoggingMiddleware);
return !$middleware instanceof LoggingMiddleware;
});
$this->entityManager->getConnection()->getConfiguration()->setMiddlewares($middlewaresWithoutLogging); $this->entityManager->getConnection()->getConfiguration()->setMiddlewares($middlewaresWithoutLogging);
if ($input->getOption('useUserId')) { if ($input->getOption('useUserId')) {

View file

@ -132,9 +132,7 @@ class EntryRestController extends WallabagRestController
} }
if (false === $returnId) { if (false === $returnId) {
$results = array_map(function ($v) { $results = array_map(fn ($v) => null !== $v, $results);
return null !== $v;
}, $results);
} }
$results = $this->replaceUrlHashes($results, $urlHashMap); $results = $this->replaceUrlHashes($results, $urlHashMap);

View file

@ -367,9 +367,7 @@ class ConfigController extends AbstractController
$backupCodes = (new BackupCodes())->toArray(); $backupCodes = (new BackupCodes())->toArray();
$backupCodesHashed = array_map( $backupCodesHashed = array_map(
function ($backupCode) { fn ($backupCode) => password_hash($backupCode, \PASSWORD_DEFAULT),
return password_hash($backupCode, \PASSWORD_DEFAULT);
},
$backupCodes $backupCodes
); );

View file

@ -89,9 +89,7 @@ abstract class WallabagMigration extends AbstractMigration
*/ */
protected function generateIdentifierName(array $columnNames, string $prefix = ''): string protected function generateIdentifierName(array $columnNames, string $prefix = ''): string
{ {
$hash = implode('', array_map(static function ($column): string { $hash = implode('', array_map(static fn ($column): string => dechex(crc32($column)), $columnNames));
return dechex(crc32($column));
}, $columnNames));
return strtoupper(substr($prefix . '_' . $hash, 0, $this->platform->getMaxIdentifierLength())); return strtoupper(substr($prefix . '_' . $hash, 0, $this->platform->getMaxIdentifierLength()));
} }

View file

@ -34,9 +34,7 @@ class AuthenticatorProvider implements ExpressionFunctionProviderInterface
function (): void { function (): void {
throw new \Exception('Not supported'); throw new \Exception('Not supported');
}, },
function (array $arguments, $uri) { fn (array $arguments, $uri) => $this->requestHtmlFunctionClient->request('GET', $uri)->getContent()
return $this->requestHtmlFunctionClient->request('GET', $uri)->getContent();
}
); );
} }

View file

@ -28,12 +28,8 @@ class ClientType extends AbstractType
$builder->get('redirect_uris') $builder->get('redirect_uris')
->addModelTransformer(new CallbackTransformer( ->addModelTransformer(new CallbackTransformer(
function ($originalUri) { fn ($originalUri) => $originalUri,
return $originalUri; fn ($submittedUri) => [$submittedUri]
},
function ($submittedUri) {
return [$submittedUri];
}
)) ))
; ;
} }

View file

@ -294,9 +294,7 @@ class DownloadImages
preg_match_all($pattern, $srcsetAttribute, $matches); preg_match_all($pattern, $srcsetAttribute, $matches);
$srcset = \call_user_func_array('array_merge', $matches); $srcset = \call_user_func_array('array_merge', $matches);
$srcsetUrls = array_map(function ($src) { $srcsetUrls = array_map(fn ($src) => trim(explode(' ', $src, 2)[0]), $srcset);
return trim(explode(' ', $src, 2)[0]);
}, $srcset);
$urls = array_merge($srcsetUrls, $urls); $urls = array_merge($srcsetUrls, $urls);
} }

View file

@ -40,13 +40,11 @@ abstract class HtmlImport extends AbstractImport
return false; return false;
} }
$entries = $hrefs->each(function (Crawler $node) { $entries = $hrefs->each(fn (Crawler $node) => [
return [
'url' => $node->attr('href'), 'url' => $node->attr('href'),
'tags' => $node->attr('tags'), 'tags' => $node->attr('tags'),
'created_at' => $node->attr('add_date'), 'created_at' => $node->attr('add_date'),
]; ]);
});
if ($this->producer) { if ($this->producer) {
$this->parseEntriesForProducer($entries); $this->parseEntriesForProducer($entries);

View file

@ -56,13 +56,11 @@ class PocketHtmlImport extends HtmlImport
return false; return false;
} }
$entries = $hrefs->each(function (Crawler $node) { $entries = $hrefs->each(fn (Crawler $node) => [
return [
'url' => $node->attr('href'), 'url' => $node->attr('href'),
'tags' => $node->attr('tags'), 'tags' => $node->attr('tags'),
'created_at' => $node->attr('time_added'), 'created_at' => $node->attr('time_added'),
]; ]);
});
if ($this->producer) { if ($this->producer) {
$this->parseEntriesForProducer($entries); $this->parseEntriesForProducer($entries);

View file

@ -289,9 +289,7 @@ class EntryRepository extends ServiceEntityRepository
if ('metadata' === $detail) { if ('metadata' === $detail) {
$fieldNames = $this->getClassMetadata()->getFieldNames(); $fieldNames = $this->getClassMetadata()->getFieldNames();
$fields = array_filter($fieldNames, function ($k) { $fields = array_filter($fieldNames, fn ($k) => 'content' !== $k);
return 'content' !== $k;
});
$qb->select(\sprintf('partial e.{%s}', implode(',', $fields))); $qb->select(\sprintf('partial e.{%s}', implode(',', $fields)));
} }

View file

@ -23,9 +23,7 @@ class TagRestControllerTest extends WallabagApiTestCase
$this->assertArrayHasKey('label', $content[0]); $this->assertArrayHasKey('label', $content[0]);
$this->assertArrayHasKey('nbEntries', $content[0]); $this->assertArrayHasKey('nbEntries', $content[0]);
$tagLabels = array_map(function ($i) { $tagLabels = array_map(fn ($i) => $i['label'], $content);
return $i['label'];
}, $content);
$this->assertNotContains($this->otherUserTagLabel, $tagLabels, 'There is a possible tag leak'); $this->assertNotContains($this->otherUserTagLabel, $tagLabels, 'There is a possible tag leak');
} }

View file

@ -95,9 +95,7 @@ class ChromeImportTest extends TestCase
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $chromeImport->setMarkAsRead(true)->import(); $res = $chromeImport->setMarkAsRead(true)->import();

View file

@ -95,9 +95,7 @@ class FirefoxImportTest extends TestCase
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $firefoxImport->setMarkAsRead(true)->import(); $res = $firefoxImport->setMarkAsRead(true)->import();

View file

@ -97,9 +97,7 @@ class InstapaperImportTest extends TestCase
$this->em $this->em
->expects($this->once()) ->expects($this->once())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $instapaperImport->setMarkAsRead(true)->import(); $res = $instapaperImport->setMarkAsRead(true)->import();

View file

@ -95,9 +95,7 @@ class PocketHtmlImportTest extends TestCase
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $pocketHtmlImport $res = $pocketHtmlImport
->setMarkAsRead(true) ->setMarkAsRead(true)

View file

@ -207,9 +207,7 @@ JSON
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived() && (bool) $persistedEntry->isStarred()));
return (bool) $persistedEntry->isArchived() && (bool) $persistedEntry->isStarred();
}));
$entry = new Entry($this->user); $entry = new Entry($this->user);
@ -299,9 +297,7 @@ JSON
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$entry = new Entry($this->user); $entry = new Entry($this->user);

View file

@ -95,9 +95,7 @@ class ReadabilityImportTest extends TestCase
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $readabilityImport->setMarkAsRead(true)->import(); $res = $readabilityImport->setMarkAsRead(true)->import();

View file

@ -95,9 +95,7 @@ class ShaarliImportTest extends TestCase
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $shaarliImport $res = $shaarliImport
->setMarkAsRead(true) ->setMarkAsRead(true)

View file

@ -99,9 +99,7 @@ class WallabagV1ImportTest extends TestCase
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $wallabagV1Import->setMarkAsRead(true)->import(); $res = $wallabagV1Import->setMarkAsRead(true)->import();

View file

@ -93,9 +93,7 @@ class WallabagV2ImportTest extends TestCase
$this->em $this->em
->expects($this->any()) ->expects($this->any())
->method('persist') ->method('persist')
->with($this->callback(function ($persistedEntry) { ->with($this->callback(fn ($persistedEntry) => (bool) $persistedEntry->isArchived()));
return (bool) $persistedEntry->isArchived();
}));
$res = $wallabagV2Import->setMarkAsRead(true)->import(); $res = $wallabagV2Import->setMarkAsRead(true)->import();