From f24cebccc2e7d0edb8919efa64d8e2adc51f9933 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:44:47 +0100 Subject: [PATCH 01/40] refactor: replace deprecated constant with suggested enum --- framework/core/src/Foundation/UninstalledSite.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Foundation/UninstalledSite.php b/framework/core/src/Foundation/UninstalledSite.php index 3fea1ad7f9..21994004b7 100644 --- a/framework/core/src/Foundation/UninstalledSite.php +++ b/framework/core/src/Foundation/UninstalledSite.php @@ -25,6 +25,7 @@ use Illuminate\View\FileViewFinder; use Monolog\Formatter\LineFormatter; use Monolog\Handler\StreamHandler; +use Monolog\Level; use Monolog\Logger; use Psr\Log\LoggerInterface; @@ -108,7 +109,7 @@ protected function getIlluminateConfig(): ConfigRepository protected function registerLogger(Container $container): void { $logPath = $this->paths->storage.'/logs/flarum-installer.log'; - $handler = new StreamHandler($logPath, Logger::DEBUG); + $handler = new StreamHandler($logPath, Level::Debug); $handler->setFormatter(new LineFormatter(null, null, true, true)); $container->instance('log', new Logger('Flarum Installer', [$handler])); From b0c5a9c49dad02357520a49e46e0625f42585dab Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:45:15 +0100 Subject: [PATCH 02/40] refactor: replace array access with foreach value --- framework/core/src/Settings/SettingsValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Settings/SettingsValidator.php b/framework/core/src/Settings/SettingsValidator.php index 8819391e8a..e87094c3ee 100644 --- a/framework/core/src/Settings/SettingsValidator.php +++ b/framework/core/src/Settings/SettingsValidator.php @@ -33,7 +33,7 @@ protected function makeValidator(array $attributes): Validator // Apply attribute specific rules. foreach ($rules as $key => $value) { - $rules[$key] = array_merge($rules[$key], $this->rules[$key] ?? []); + $rules[$key] = array_merge($value, $this->rules[$key] ?? []); } $validator = $this->validator->make($attributes, $rules, $this->getMessages()); From 2d0b261c1771c35c5fadcd18878f56c07131c5ba Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:24:47 +0100 Subject: [PATCH 03/40] refactor: make classes readonly instead of marking every property --- framework/core/src/Console/Server.php | 4 ++-- framework/core/src/Extend/Locales.php | 4 ++-- framework/core/src/Foundation/Config.php | 4 ++-- .../src/Foundation/ErrorHandling/JsonApiFormatter.php | 4 ++-- .../core/src/Foundation/ErrorHandling/Registry.php | 8 ++++---- framework/core/src/Frontend/Content/CorePayload.php | 8 ++++---- framework/core/src/Frontend/Content/Meta.php | 4 ++-- .../src/Http/Middleware/CheckForMaintenanceMode.php | 6 +++--- framework/core/src/Http/Server.php | 4 ++-- framework/core/src/Install/AdminUser.php | 8 ++++---- framework/core/src/Install/Steps/ConnectToDatabase.php | 8 ++++---- framework/core/src/Install/Steps/CreateAdminUser.php | 8 ++++---- framework/core/src/Install/Steps/PublishAssets.php | 6 +++--- framework/core/src/Install/Steps/RunMigrations.php | 8 ++++---- framework/core/src/Install/Steps/StoreConfig.php | 10 +++++----- framework/core/src/Install/Steps/WriteSettings.php | 6 +++--- framework/core/src/Mail/LogDriver.php | 4 ++-- .../Notification/Driver/AlertNotificationDriver.php | 4 ++-- .../Notification/Driver/EmailNotificationDriver.php | 4 ++-- framework/core/src/Queue/ExceptionHandler.php | 4 ++-- 20 files changed, 58 insertions(+), 58 deletions(-) diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index fa61d3a923..fe39e8385f 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -23,10 +23,10 @@ use Symfony\Component\Console\Event\ConsoleTerminateEvent; use Symfony\Component\EventDispatcher\EventDispatcher; -class Server +readonly class Server { public function __construct( - private readonly SiteInterface $site + private SiteInterface $site ) { } diff --git a/framework/core/src/Extend/Locales.php b/framework/core/src/Extend/Locales.php index 83bed9eac9..73863e5cc9 100644 --- a/framework/core/src/Extend/Locales.php +++ b/framework/core/src/Extend/Locales.php @@ -15,13 +15,13 @@ use Illuminate\Contracts\Container\Container; use Symfony\Component\Translation\MessageCatalogueInterface; -class Locales implements ExtenderInterface, LifecycleInterface +readonly class Locales implements ExtenderInterface, LifecycleInterface { /** * @param string $directory: Directory of the locale files. */ public function __construct( - private readonly string $directory + private string $directory ) { } diff --git a/framework/core/src/Foundation/Config.php b/framework/core/src/Foundation/Config.php index 3e53ad7a61..633d4731b8 100644 --- a/framework/core/src/Foundation/Config.php +++ b/framework/core/src/Foundation/Config.php @@ -16,10 +16,10 @@ use Psr\Http\Message\UriInterface; use RuntimeException; -class Config implements ArrayAccess +readonly class Config implements ArrayAccess { public function __construct( - private readonly array $data + private array $data ) { $this->requireKeys('url'); } diff --git a/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php b/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php index 456cd8e58c..d7580e8120 100644 --- a/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/JsonApiFormatter.php @@ -18,10 +18,10 @@ * * See https://jsonapi.org/format/1.0/#errors. */ -class JsonApiFormatter implements HttpFormatter +readonly class JsonApiFormatter implements HttpFormatter { public function __construct( - private readonly bool $includeTrace = false + private bool $includeTrace = false ) { } diff --git a/framework/core/src/Foundation/ErrorHandling/Registry.php b/framework/core/src/Foundation/ErrorHandling/Registry.php index 0c8a551206..74a8bb0831 100644 --- a/framework/core/src/Foundation/ErrorHandling/Registry.php +++ b/framework/core/src/Foundation/ErrorHandling/Registry.php @@ -19,12 +19,12 @@ * of it, map them to error "types" and how to determine appropriate HTTP status * codes for them. */ -class Registry +readonly class Registry { public function __construct( - private readonly array $statusMap, - private readonly array $classMap, - private readonly array $handlerMap + private array $statusMap, + private array $classMap, + private array $handlerMap ) { } diff --git a/framework/core/src/Frontend/Content/CorePayload.php b/framework/core/src/Frontend/Content/CorePayload.php index ca72aee386..67f95de101 100644 --- a/framework/core/src/Frontend/Content/CorePayload.php +++ b/framework/core/src/Frontend/Content/CorePayload.php @@ -17,12 +17,12 @@ use Flarum\Settings\SettingsRepositoryInterface; use Psr\Http\Message\ServerRequestInterface as Request; -class CorePayload +readonly class CorePayload { public function __construct( - private readonly LocaleManager $locales, - private readonly MaintenanceMode $maintenance, - private readonly SettingsRepositoryInterface $settings + private LocaleManager $locales, + private MaintenanceMode $maintenance, + private SettingsRepositoryInterface $settings ) { } diff --git a/framework/core/src/Frontend/Content/Meta.php b/framework/core/src/Frontend/Content/Meta.php index fd422d0e6f..dee9ad6d52 100644 --- a/framework/core/src/Frontend/Content/Meta.php +++ b/framework/core/src/Frontend/Content/Meta.php @@ -14,10 +14,10 @@ use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface as Request; -class Meta +readonly class Meta { public function __construct( - private readonly LocaleManager $locales + private LocaleManager $locales ) { } diff --git a/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php b/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php index 808627735a..9941b67ce5 100644 --- a/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php +++ b/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php @@ -17,11 +17,11 @@ use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -class CheckForMaintenanceMode implements MiddlewareInterface +readonly class CheckForMaintenanceMode implements MiddlewareInterface { public function __construct( - private readonly MaintenanceMode $maintenance, - private readonly array $exemptRoutes, + private MaintenanceMode $maintenance, + private array $exemptRoutes, ) { } diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index d8c43208bb..959f9d2af7 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -21,10 +21,10 @@ use Psr\Log\LoggerInterface; use Throwable; -class Server +readonly class Server { public function __construct( - private readonly SiteInterface $site + private SiteInterface $site ) { } diff --git a/framework/core/src/Install/AdminUser.php b/framework/core/src/Install/AdminUser.php index f032c51d80..94f31259c8 100644 --- a/framework/core/src/Install/AdminUser.php +++ b/framework/core/src/Install/AdminUser.php @@ -12,12 +12,12 @@ use Carbon\Carbon; use Illuminate\Hashing\BcryptHasher; -class AdminUser +readonly class AdminUser { public function __construct( - private readonly string $username, - private readonly string $password, - private readonly string $email + private string $username, + private string $password, + private string $email ) { $this->validate(); } diff --git a/framework/core/src/Install/Steps/ConnectToDatabase.php b/framework/core/src/Install/Steps/ConnectToDatabase.php index 8e66328a3e..9511432d96 100644 --- a/framework/core/src/Install/Steps/ConnectToDatabase.php +++ b/framework/core/src/Install/Steps/ConnectToDatabase.php @@ -24,12 +24,12 @@ use InvalidArgumentException; use RangeException; -class ConnectToDatabase implements Step +readonly class ConnectToDatabase implements Step { public function __construct( - private readonly DatabaseConfig $dbConfig, - private readonly Closure $store, - private readonly string $basePath + private DatabaseConfig $dbConfig, + private Closure $store, + private string $basePath ) { } diff --git a/framework/core/src/Install/Steps/CreateAdminUser.php b/framework/core/src/Install/Steps/CreateAdminUser.php index 1f94217ca3..92b994a8c6 100644 --- a/framework/core/src/Install/Steps/CreateAdminUser.php +++ b/framework/core/src/Install/Steps/CreateAdminUser.php @@ -15,12 +15,12 @@ use Flarum\Install\Step; use Illuminate\Database\ConnectionInterface; -class CreateAdminUser implements Step +readonly class CreateAdminUser implements Step { public function __construct( - private readonly ConnectionInterface $database, - private readonly AdminUser $admin, - private readonly ?string $accessToken = null + private ConnectionInterface $database, + private AdminUser $admin, + private ?string $accessToken = null ) { } diff --git a/framework/core/src/Install/Steps/PublishAssets.php b/framework/core/src/Install/Steps/PublishAssets.php index 19755816fb..2618f4792c 100644 --- a/framework/core/src/Install/Steps/PublishAssets.php +++ b/framework/core/src/Install/Steps/PublishAssets.php @@ -12,11 +12,11 @@ use Flarum\Install\ReversibleStep; use Illuminate\Filesystem\Filesystem; -class PublishAssets implements ReversibleStep +readonly class PublishAssets implements ReversibleStep { public function __construct( - private readonly string $vendorPath, - private readonly string $assetPath + private string $vendorPath, + private string $assetPath ) { } diff --git a/framework/core/src/Install/Steps/RunMigrations.php b/framework/core/src/Install/Steps/RunMigrations.php index 09dc387073..5d306c54c5 100644 --- a/framework/core/src/Install/Steps/RunMigrations.php +++ b/framework/core/src/Install/Steps/RunMigrations.php @@ -15,12 +15,12 @@ use Illuminate\Database\ConnectionInterface; use Illuminate\Filesystem\Filesystem; -class RunMigrations implements Step +readonly class RunMigrations implements Step { public function __construct( - private readonly ConnectionInterface $database, - private readonly string $driver, - private readonly string $path + private ConnectionInterface $database, + private string $driver, + private string $path ) { } diff --git a/framework/core/src/Install/Steps/StoreConfig.php b/framework/core/src/Install/Steps/StoreConfig.php index 596482b04f..cd5cf82d8b 100644 --- a/framework/core/src/Install/Steps/StoreConfig.php +++ b/framework/core/src/Install/Steps/StoreConfig.php @@ -13,13 +13,13 @@ use Flarum\Install\DatabaseConfig; use Flarum\Install\ReversibleStep; -class StoreConfig implements ReversibleStep +readonly class StoreConfig implements ReversibleStep { public function __construct( - private readonly bool $debugMode, - private readonly DatabaseConfig $dbConfig, - private readonly BaseUrl $baseUrl, - private readonly string $configFile + private bool $debugMode, + private DatabaseConfig $dbConfig, + private BaseUrl $baseUrl, + private string $configFile ) { } diff --git a/framework/core/src/Install/Steps/WriteSettings.php b/framework/core/src/Install/Steps/WriteSettings.php index e4bb582e0a..2c12ce5da6 100644 --- a/framework/core/src/Install/Steps/WriteSettings.php +++ b/framework/core/src/Install/Steps/WriteSettings.php @@ -14,11 +14,11 @@ use Flarum\Settings\DatabaseSettingsRepository; use Illuminate\Database\ConnectionInterface; -class WriteSettings implements Step +readonly class WriteSettings implements Step { public function __construct( - private readonly ConnectionInterface $database, - private readonly array $custom + private ConnectionInterface $database, + private array $custom ) { } diff --git a/framework/core/src/Mail/LogDriver.php b/framework/core/src/Mail/LogDriver.php index 8547738906..6e2a6299be 100644 --- a/framework/core/src/Mail/LogDriver.php +++ b/framework/core/src/Mail/LogDriver.php @@ -15,10 +15,10 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Mailer\Transport\TransportInterface; -class LogDriver implements DriverInterface +readonly class LogDriver implements DriverInterface { public function __construct( - private readonly LoggerInterface $logger + private LoggerInterface $logger ) { } diff --git a/framework/core/src/Notification/Driver/AlertNotificationDriver.php b/framework/core/src/Notification/Driver/AlertNotificationDriver.php index 8019135ee8..f769fc1c7e 100644 --- a/framework/core/src/Notification/Driver/AlertNotificationDriver.php +++ b/framework/core/src/Notification/Driver/AlertNotificationDriver.php @@ -16,10 +16,10 @@ use Illuminate\Contracts\Queue\Queue; use ReflectionClass; -class AlertNotificationDriver implements NotificationDriverInterface +readonly class AlertNotificationDriver implements NotificationDriverInterface { public function __construct( - private readonly Queue $queue + private Queue $queue ) { } diff --git a/framework/core/src/Notification/Driver/EmailNotificationDriver.php b/framework/core/src/Notification/Driver/EmailNotificationDriver.php index f0ea53344e..59dd0b9a6f 100644 --- a/framework/core/src/Notification/Driver/EmailNotificationDriver.php +++ b/framework/core/src/Notification/Driver/EmailNotificationDriver.php @@ -16,10 +16,10 @@ use Illuminate\Contracts\Queue\Queue; use ReflectionClass; -class EmailNotificationDriver implements NotificationDriverInterface +readonly class EmailNotificationDriver implements NotificationDriverInterface { public function __construct( - private readonly Queue $queue + private Queue $queue ) { } diff --git a/framework/core/src/Queue/ExceptionHandler.php b/framework/core/src/Queue/ExceptionHandler.php index 9733578345..3dc23f0229 100644 --- a/framework/core/src/Queue/ExceptionHandler.php +++ b/framework/core/src/Queue/ExceptionHandler.php @@ -13,10 +13,10 @@ use Psr\Log\LoggerInterface; use Throwable; -class ExceptionHandler implements ExceptionHandling +readonly class ExceptionHandler implements ExceptionHandling { public function __construct( - private readonly LoggerInterface $logger + private LoggerInterface $logger ) { } From fcf7a7f29f7dc7f866a16d2f5b1f4ed8b8aef71b Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:27:46 +0100 Subject: [PATCH 04/40] refactor: turn complicated foreach into a clean array_map --- .../src/Api/Endpoint/Concerns/HasEagerLoading.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php b/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php index 19c3bb4f82..0c319c600f 100644 --- a/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php +++ b/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php @@ -147,13 +147,10 @@ protected function compileSimpleEagerLoads(Context $context, array $included): a protected function compileWhereEagerLoads(Context $context): array { - $relations = []; - - foreach ($this->loadRelationWhere as $name => $callable) { - $relations[$name] = function ($query) use ($callable, $context) { - $callable($query, $context); - }; - } + $relations = array_map( + callback: fn ($callable) => fn ($query) => $callable($query, $context), + array: $this->loadRelationWhere + ); return $relations; } From 665261a810f83a2cffb7dbb85ae823b0dadc44d3 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:28:20 +0100 Subject: [PATCH 05/40] refactor: sort arguments --- framework/core/src/User/AccountActivationMailerTrait.php | 4 ++-- framework/core/src/User/EmailConfirmationMailer.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/core/src/User/AccountActivationMailerTrait.php b/framework/core/src/User/AccountActivationMailerTrait.php index 2038b04580..64bb6462c2 100644 --- a/framework/core/src/User/AccountActivationMailerTrait.php +++ b/framework/core/src/User/AccountActivationMailerTrait.php @@ -41,10 +41,10 @@ protected function sendConfirmationEmail(User $user, array $data): void $this->queue->push(new SendInformationalEmailJob( email: $user->email, + displayName: Arr::get($data, 'username'), subject: $subject, body: $body, - forumTitle: Arr::get($data, 'forum'), - displayName: Arr::get($data, 'username') + forumTitle: Arr::get($data, 'forum') )); } } diff --git a/framework/core/src/User/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php index 221d9e4c57..207a557047 100644 --- a/framework/core/src/User/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -37,10 +37,10 @@ public function handle(EmailChangeRequested $event): void $this->queue->push(new SendInformationalEmailJob( email: $email, - subject:$subject, + displayName: Arr::get($data, 'username'), + subject: $subject, body: $body, - forumTitle: Arr::get($data, 'forum'), - displayName: Arr::get($data, 'username') + forumTitle: Arr::get($data, 'forum') )); } From fdf5890fb6338f1bd4085b9c810dd623c4099040 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:29:09 +0100 Subject: [PATCH 06/40] refactor: use PHP ^8.0 str_* methods --- framework/core/src/Install/Prerequisite/WritablePaths.php | 2 +- framework/core/src/User/User.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Install/Prerequisite/WritablePaths.php b/framework/core/src/Install/Prerequisite/WritablePaths.php index 91ca121904..0bf44cb9e1 100644 --- a/framework/core/src/Install/Prerequisite/WritablePaths.php +++ b/framework/core/src/Install/Prerequisite/WritablePaths.php @@ -71,7 +71,7 @@ private function getAbsolutePath(string $path): string } } - return (substr($path, 0, 1) == '/' ? '/' : '').implode(DIRECTORY_SEPARATOR, $absolutes); + return (str_starts_with($path, '/') ? '/' : '').implode(DIRECTORY_SEPARATOR, $absolutes); } private function normalize(array $paths): Collection diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index a22bff8c48..d30ddb9f54 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -315,7 +315,7 @@ public function hasPermissionLike(string $match): bool } foreach ($this->getPermissions() as $permission) { - if (substr($permission, -strlen($match)) === $match) { + if (str_ends_with($permission, $match)) { return true; } } From 372a422be988cf9fbf0292dbb9aa5e1bb90ef1a8 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:30:36 +0100 Subject: [PATCH 07/40] refactor: remove redundant casts --- framework/core/src/Extension/Extension.php | 2 +- framework/core/src/Post/PostRepository.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Extension/Extension.php b/framework/core/src/Extension/Extension.php index c44f1e1532..963b57c012 100644 --- a/framework/core/src/Extension/Extension.php +++ b/framework/core/src/Extension/Extension.php @@ -452,7 +452,7 @@ public function migrate(Migrator $migrator, string $direction = 'up'): ?int */ public function toArray(): array { - return (array) array_merge([ + return array_merge([ 'id' => $this->getId(), 'version' => $this->getVersion(), 'path' => $this->getPath(), diff --git a/framework/core/src/Post/PostRepository.php b/framework/core/src/Post/PostRepository.php index 6ac36c71d0..fdd47d29d5 100644 --- a/framework/core/src/Post/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -60,7 +60,7 @@ public function findWhere(array $where = [], ?User $actor = null, array $sort = ->skip($start) ->take($count); - foreach ((array) $sort as $field => $order) { + foreach ($sort as $field => $order) { $query->orderBy($field, $order); } @@ -100,7 +100,7 @@ public function getIndexForNumber(int $discussionId, int $number, ?User $actor = // We don't add $number as a binding because for some // reason doing so makes the bindings go out of order. - ->orderByRaw('ABS(CAST(number AS SIGNED) - '.(int) $number.')'); + ->orderByRaw('ABS(CAST(number AS SIGNED) - '. $number .')'); }); return $query->count(); From ef7a64e696e3d0f306dac3ae587f17d6531448c9 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:31:18 +0100 Subject: [PATCH 08/40] refactor: remove double-check --- framework/core/src/Http/Middleware/RememberFromCookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Http/Middleware/RememberFromCookie.php b/framework/core/src/Http/Middleware/RememberFromCookie.php index c5d8315f62..6623a504e0 100644 --- a/framework/core/src/Http/Middleware/RememberFromCookie.php +++ b/framework/core/src/Http/Middleware/RememberFromCookie.php @@ -32,7 +32,7 @@ public function process(Request $request, Handler $handler): Response if ($id) { $token = AccessToken::findValid($id); - if ($token && $token instanceof RememberAccessToken) { + if ($token instanceof RememberAccessToken) { $token->touch(request: $request); /** @var \Illuminate\Contracts\Session\Session $session */ From 63f3a65bc54b6f5ff0146077bc65f887df7fb561 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:36:53 +0100 Subject: [PATCH 09/40] refactor: make property readonly --- framework/core/src/Foundation/ErrorHandling/HandledError.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Foundation/ErrorHandling/HandledError.php b/framework/core/src/Foundation/ErrorHandling/HandledError.php index 5b7fa73492..b1316355a1 100644 --- a/framework/core/src/Foundation/ErrorHandling/HandledError.php +++ b/framework/core/src/Foundation/ErrorHandling/HandledError.php @@ -31,7 +31,7 @@ public function __construct( private readonly Throwable $error, private readonly string $type, private readonly int $statusCode, - private bool $report = false + private readonly bool $report = false ) { } From f8cef83a7e80c9e38b5ef5d8f445a424b8c9ac01 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:41:34 +0100 Subject: [PATCH 10/40] refactor: use nullsafe operator --- framework/core/src/Database/Migrator.php | 2 +- framework/core/src/Discussion/DiscussionMetadataUpdater.php | 6 +++--- framework/core/src/User/UserMetadataUpdater.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index 11e7c50e46..a25362d121 100644 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -115,7 +115,7 @@ protected function runUp(string $path, string $file, ?Extension $extension = nul public function reset(string $path, ?Extension $extension = null): int { $migrations = array_reverse($this->repository->getRan( - $extension ? $extension->getId() : null + $extension?->getId() )); $count = count($migrations); diff --git a/framework/core/src/Discussion/DiscussionMetadataUpdater.php b/framework/core/src/Discussion/DiscussionMetadataUpdater.php index 3e9966ab2e..c392084408 100644 --- a/framework/core/src/Discussion/DiscussionMetadataUpdater.php +++ b/framework/core/src/Discussion/DiscussionMetadataUpdater.php @@ -30,7 +30,7 @@ public function whenPostWasPosted(Posted $event): void { $discussion = $event->post->discussion; - if ($discussion && $discussion->exists) { + if ($discussion?->exists) { $discussion->refreshCommentCount(); $discussion->refreshLastPost(); $discussion->refreshParticipantCount(); @@ -58,7 +58,7 @@ public function whenPostWasRestored(Restored $event): void { $discussion = $event->post->discussion; - if ($discussion && $discussion->exists) { + if ($discussion?->exists) { $discussion->refreshCommentCount(); $discussion->refreshParticipantCount(); $discussion->refreshLastPost(); @@ -70,7 +70,7 @@ protected function removePost(Post $post): void { $discussion = $post->discussion; - if ($discussion && $discussion->exists) { + if ($discussion?->exists) { $discussion->refreshCommentCount(); $discussion->refreshParticipantCount(); diff --git a/framework/core/src/User/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php index 3f9290b739..49f026a9a5 100644 --- a/framework/core/src/User/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -49,7 +49,7 @@ public function whenDiscussionWasDeleted(DiscussionDeleted $event): void private function updateCommentsCount(?User $user): void { - if ($user && $user->exists) { + if ($user?->exists) { $user->refreshCommentCount()->save(); } } @@ -58,7 +58,7 @@ private function updateDiscussionsCount(Discussion $discussion): void { $user = $discussion->user; - if ($user && $user->exists) { + if ($user?->exists) { $user->refreshDiscussionCount()->save(); } } From 2454fa0b8091c86f1037011dc29948400fe8556c Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:43:24 +0100 Subject: [PATCH 11/40] refactor: flip yoda-style comparison for consistency --- framework/core/src/Install/Prerequisite/WritablePaths.php | 4 ++-- framework/core/src/Locale/Translator.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Install/Prerequisite/WritablePaths.php b/framework/core/src/Install/Prerequisite/WritablePaths.php index 0bf44cb9e1..731bb56059 100644 --- a/framework/core/src/Install/Prerequisite/WritablePaths.php +++ b/framework/core/src/Install/Prerequisite/WritablePaths.php @@ -61,10 +61,10 @@ private function getAbsolutePath(string $path): string $absolutes = []; foreach ($parts as $part) { - if ('.' == $part) { + if ($part == '.') { continue; } - if ('..' == $part) { + if ($part == '..') { array_pop($absolutes); } else { $absolutes[] = $part; diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index 11948c49f6..7e41162bbe 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -29,7 +29,7 @@ public function choice($key, $number, array $replace = [], $locale = null): stri public function getCatalogue(?string $locale = null): MessageCatalogueInterface { - if (null === $locale) { + if ($locale === null) { $locale = $this->getLocale(); } else { $this->assertValidLocale($locale); From 12ba0b173f0bbd5c5fb1a2162e76308e9bf819e9 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:48:25 +0100 Subject: [PATCH 12/40] refactor: mark sensitive parameters with SensitiveParameter attribute --- .../core/src/Api/Resource/AccessTokenResource.php | 8 ++++---- framework/core/src/Api/Resource/UserResource.php | 4 ++-- .../core/src/Http/Access/AccessTokenPolicy.php | 2 +- framework/core/src/Http/AccessToken.php | 2 +- .../core/src/Http/Event/DeveloperTokenCreated.php | 2 +- framework/core/src/Http/Rememberer.php | 2 +- framework/core/src/Http/SessionAuthenticator.php | 2 +- framework/core/src/Install/AdminUser.php | 6 +++--- framework/core/src/Install/DatabaseConfig.php | 14 +++++++------- framework/core/src/Install/Installation.php | 2 +- .../core/src/Install/Steps/CreateAdminUser.php | 2 +- .../core/src/User/AccountActivationMailerTrait.php | 2 +- framework/core/src/User/Command/ConfirmEmail.php | 4 +++- framework/core/src/User/Event/LoggedIn.php | 2 +- framework/core/src/User/RegistrationToken.php | 2 +- framework/core/src/User/User.php | 4 ++-- framework/core/src/User/UserServiceProvider.php | 2 +- 17 files changed, 32 insertions(+), 30 deletions(-) diff --git a/framework/core/src/Api/Resource/AccessTokenResource.php b/framework/core/src/Api/Resource/AccessTokenResource.php index e6f487550c..1a0f5492be 100644 --- a/framework/core/src/Api/Resource/AccessTokenResource.php +++ b/framework/core/src/Api/Resource/AccessTokenResource.php @@ -79,18 +79,18 @@ public function fields(): array { return [ Schema\Str::make('token') - ->visible(function (AccessToken $token, Context $context) { + ->visible(function (#[\SensitiveParameter] AccessToken $token, Context $context) { return $context->getActor()->id === $token->user_id && ! in_array('token', $token->getHidden(), true); }), Schema\Integer::make('userId'), Schema\DateTime::make('createdAt'), Schema\DateTime::make('lastActivityAt'), Schema\Boolean::make('isCurrent') - ->get(function (AccessToken $token, Context $context) { + ->get(function (#[\SensitiveParameter] AccessToken $token, Context $context) { return $token->token === $context->request->getAttribute('session')->get('access_token'); }), Schema\Boolean::make('isSessionToken') - ->get(function (AccessToken $token) { + ->get(function (#[\SensitiveParameter] AccessToken $token) { return in_array($token->type, [SessionAccessToken::$type, RememberAccessToken::$type], true); }), Schema\Str::make('title') @@ -99,7 +99,7 @@ public function fields(): array ->maxLength(255), Schema\Str::make('lastIpAddress'), Schema\Str::make('device') - ->get(function (AccessToken $token) { + ->get(function (#[\SensitiveParameter] AccessToken $token) { $agent = new Agent(); $agent->setUserAgent($token->last_user_agent); diff --git a/framework/core/src/Api/Resource/UserResource.php b/framework/core/src/Api/Resource/UserResource.php index 5160dc3eba..2f9ac808db 100644 --- a/framework/core/src/Api/Resource/UserResource.php +++ b/framework/core/src/Api/Resource/UserResource.php @@ -377,7 +377,7 @@ public function saving(object $model, \Tobyz\JsonApiServer\Context $context): ?o return $model; } - private function applyToken(User $user, RegistrationToken $token): void + private function applyToken(User $user, #[\SensitiveParameter] RegistrationToken $token): void { foreach ($token->user_attributes as $k => $v) { if ($k === 'avatar_url') { @@ -446,7 +446,7 @@ private function retrieveAvatarFromUrl(string $url): ?string return $response->getBody()->getContents(); } - private function fulfillToken(User $user, RegistrationToken $token): void + private function fulfillToken(User $user, #[\SensitiveParameter] RegistrationToken $token): void { $token->delete(); diff --git a/framework/core/src/Http/Access/AccessTokenPolicy.php b/framework/core/src/Http/Access/AccessTokenPolicy.php index fc74195362..614fb83fb9 100644 --- a/framework/core/src/Http/Access/AccessTokenPolicy.php +++ b/framework/core/src/Http/Access/AccessTokenPolicy.php @@ -15,7 +15,7 @@ class AccessTokenPolicy extends AbstractPolicy { - public function revoke(User $actor, AccessToken $token): ?string + public function revoke(User $actor, #[\SensitiveParameter] AccessToken $token): ?string { if ($token->user_id === $actor->id || $actor->hasPermission('moderateAccessTokens')) { return $this->allow(); diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php index 8de6b3b61a..cc42186c62 100644 --- a/framework/core/src/Http/AccessToken.php +++ b/framework/core/src/Http/AccessToken.php @@ -165,7 +165,7 @@ protected static function scopeExpired(Builder $query, Carbon $date): void * Shortcut to find a valid token. * @param string $token Token as sent by the user. We allow non-string values like null so we can directly feed any value from a request. */ - public static function findValid(string $token): ?AccessToken + public static function findValid(#[\SensitiveParameter] string $token): ?AccessToken { return static::query()->whereValid()->where('token', $token)->first(); } diff --git a/framework/core/src/Http/Event/DeveloperTokenCreated.php b/framework/core/src/Http/Event/DeveloperTokenCreated.php index ec6839e9aa..be3e7c4a35 100644 --- a/framework/core/src/Http/Event/DeveloperTokenCreated.php +++ b/framework/core/src/Http/Event/DeveloperTokenCreated.php @@ -14,7 +14,7 @@ class DeveloperTokenCreated { public function __construct( - public AccessToken $token + #[\SensitiveParameter] public AccessToken $token ) { } } diff --git a/framework/core/src/Http/Rememberer.php b/framework/core/src/Http/Rememberer.php index 24dc23d904..434a070780 100644 --- a/framework/core/src/Http/Rememberer.php +++ b/framework/core/src/Http/Rememberer.php @@ -24,7 +24,7 @@ public function __construct( /** * Sets the remember cookie on a response. */ - public function remember(ResponseInterface $response, RememberAccessToken $token): ResponseInterface + public function remember(ResponseInterface $response, #[\SensitiveParameter] RememberAccessToken $token): ResponseInterface { return FigResponseCookies::set( $response, diff --git a/framework/core/src/Http/SessionAuthenticator.php b/framework/core/src/Http/SessionAuthenticator.php index 35ee76753f..66f83b706d 100644 --- a/framework/core/src/Http/SessionAuthenticator.php +++ b/framework/core/src/Http/SessionAuthenticator.php @@ -13,7 +13,7 @@ class SessionAuthenticator { - public function logIn(Session $session, AccessToken $token): void + public function logIn(Session $session, #[\SensitiveParameter] AccessToken $token): void { $session->regenerate(true); $session->put('access_token', $token->token); diff --git a/framework/core/src/Install/AdminUser.php b/framework/core/src/Install/AdminUser.php index 94f31259c8..3712ca08c9 100644 --- a/framework/core/src/Install/AdminUser.php +++ b/framework/core/src/Install/AdminUser.php @@ -15,9 +15,9 @@ readonly class AdminUser { public function __construct( - private string $username, - private string $password, - private string $email + private string $username, + #[\SensitiveParameter] private string $password, + private string $email ) { $this->validate(); } diff --git a/framework/core/src/Install/DatabaseConfig.php b/framework/core/src/Install/DatabaseConfig.php index 325bff6aad..003bbcbc8d 100644 --- a/framework/core/src/Install/DatabaseConfig.php +++ b/framework/core/src/Install/DatabaseConfig.php @@ -15,13 +15,13 @@ class DatabaseConfig implements Arrayable { public function __construct( - private readonly string $driver, - private readonly ?string $host, - private readonly int $port, - private string $database, - private readonly ?string $username, - private readonly ?string $password, - private readonly ?string $prefix + private readonly string $driver, + private readonly ?string $host, + private readonly int $port, + private string $database, + private readonly ?string $username, + #[\SensitiveParameter] private readonly ?string $password, + private readonly ?string $prefix ) { $this->validate(); } diff --git a/framework/core/src/Install/Installation.php b/framework/core/src/Install/Installation.php index 68926ee04e..6a821c2b93 100644 --- a/framework/core/src/Install/Installation.php +++ b/framework/core/src/Install/Installation.php @@ -82,7 +82,7 @@ public function adminUser(AdminUser $admin): self return $this; } - public function accessToken(string $token): self + public function accessToken(#[\SensitiveParameter] string $token): self { $this->accessToken = $token; diff --git a/framework/core/src/Install/Steps/CreateAdminUser.php b/framework/core/src/Install/Steps/CreateAdminUser.php index 92b994a8c6..d44e01a11f 100644 --- a/framework/core/src/Install/Steps/CreateAdminUser.php +++ b/framework/core/src/Install/Steps/CreateAdminUser.php @@ -20,7 +20,7 @@ public function __construct( private ConnectionInterface $database, private AdminUser $admin, - private ?string $accessToken = null + #[\SensitiveParameter] private ?string $accessToken = null ) { } diff --git a/framework/core/src/User/AccountActivationMailerTrait.php b/framework/core/src/User/AccountActivationMailerTrait.php index 64bb6462c2..7ff13ced54 100644 --- a/framework/core/src/User/AccountActivationMailerTrait.php +++ b/framework/core/src/User/AccountActivationMailerTrait.php @@ -25,7 +25,7 @@ protected function generateToken(User $user, string $email): EmailToken /** * Get the data that should be made available to email templates. */ - protected function getEmailData(User $user, EmailToken $token): array + protected function getEmailData(User $user, #[\SensitiveParameter] EmailToken $token): array { return [ 'username' => $user->display_name, diff --git a/framework/core/src/User/Command/ConfirmEmail.php b/framework/core/src/User/Command/ConfirmEmail.php index 626653a463..71df2d12e4 100644 --- a/framework/core/src/User/Command/ConfirmEmail.php +++ b/framework/core/src/User/Command/ConfirmEmail.php @@ -9,13 +9,15 @@ namespace Flarum\User\Command; +use SensitiveParameter; + class ConfirmEmail { public function __construct( /** * The email confirmation token. */ - public string $token + #[SensitiveParameter] public string $token ) { } } diff --git a/framework/core/src/User/Event/LoggedIn.php b/framework/core/src/User/Event/LoggedIn.php index be4404cfd0..ebc9efbd0e 100644 --- a/framework/core/src/User/Event/LoggedIn.php +++ b/framework/core/src/User/Event/LoggedIn.php @@ -16,7 +16,7 @@ class LoggedIn { public function __construct( public User $user, - public AccessToken $token + #[\SensitiveParameter] public AccessToken $token ) { } } diff --git a/framework/core/src/User/RegistrationToken.php b/framework/core/src/User/RegistrationToken.php index 069ad0a061..c4bf3dd114 100644 --- a/framework/core/src/User/RegistrationToken.php +++ b/framework/core/src/User/RegistrationToken.php @@ -64,7 +64,7 @@ public static function generate(string $provider, string $identifier, array $att * * @throws InvalidConfirmationTokenException */ - public function scopeValidOrFail(Builder $query, string $token): ?RegistrationToken + public function scopeValidOrFail(Builder $query, #[\SensitiveParameter] string $token): ?RegistrationToken { /** @var RegistrationToken|null $token */ $token = $query->find($token); diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index d30ddb9f54..e5ab88a328 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -207,7 +207,7 @@ public function requestEmailChange(string $email): static return $this; } - public function changePassword(string $password): static + public function changePassword(#[\SensitiveParameter] string $password): static { $this->password = $password; @@ -267,7 +267,7 @@ public function getDisplayNameAttribute(): string return static::$displayNameDriver->displayName($this); } - public function checkPassword(string $password): bool + public function checkPassword(#[\SensitiveParameter] string $password): bool { $valid = false; diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index 524871feaa..1c3477e633 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -91,7 +91,7 @@ protected function registerPasswordCheckers(): void { $this->container->singleton('flarum.user.password_checkers', function (Container $container) { return [ - 'standard' => function (User $user, $password) use ($container) { + 'standard' => function (User $user, #[\SensitiveParameter] $password) use ($container) { if ($container->make('hash')->check($password, $user->password)) { return true; } From 5e84a42cddaedfcd95ae3ee6fcf05756ac3983e0 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:49:20 +0100 Subject: [PATCH 13/40] refactor: use strict comparison --- framework/core/src/Extension/Extension.php | 2 +- framework/core/src/Foundation/Concerns/InteractsWithLaravel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Extension/Extension.php b/framework/core/src/Extension/Extension.php index 963b57c012..ef4d50ed80 100644 --- a/framework/core/src/Extension/Extension.php +++ b/framework/core/src/Extension/Extension.php @@ -436,7 +436,7 @@ public function migrate(Migrator $migrator, string $direction = 'up'): ?int return null; } - if ($direction == 'up') { + if ($direction === 'up') { $migrator->run($this->getPath().'/migrations', $this); } else { return $migrator->reset($this->getPath().'/migrations', $this); diff --git a/framework/core/src/Foundation/Concerns/InteractsWithLaravel.php b/framework/core/src/Foundation/Concerns/InteractsWithLaravel.php index fac19739c8..350b49e264 100644 --- a/framework/core/src/Foundation/Concerns/InteractsWithLaravel.php +++ b/framework/core/src/Foundation/Concerns/InteractsWithLaravel.php @@ -216,6 +216,6 @@ public function shouldSkipMiddleware(): bool public function joinPaths(string $basePath, string $path = ''): string { - return $basePath.($path != '' ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : ''); + return $basePath.($path !== '' ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : ''); } } From 5405a22f75422282d49712ba89ec43b16b385c80 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:49:42 +0100 Subject: [PATCH 14/40] refactor: use first-class-callable --- framework/core/src/Admin/Content/AdminPayload.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/framework/core/src/Admin/Content/AdminPayload.php b/framework/core/src/Admin/Content/AdminPayload.php index 134340a552..2450dda4b6 100644 --- a/framework/core/src/Admin/Content/AdminPayload.php +++ b/framework/core/src/Admin/Content/AdminPayload.php @@ -54,9 +54,7 @@ public function __invoke(Document $document, Request $request): void $document->payload['extensions'] = $this->extensions->getExtensions()->toArray(); $document->payload['displayNameDrivers'] = array_keys($this->container->make('flarum.user.display_name.supported_drivers')); - $document->payload['slugDrivers'] = array_map(function ($resourceDrivers) { - return array_keys($resourceDrivers); - }, $this->container->make('flarum.http.slugDrivers')); + $document->payload['slugDrivers'] = array_map(array_keys(...), $this->container->make('flarum.http.slugDrivers')); $document->payload['searchDrivers'] = $this->getSearchDrivers(); $document->payload['phpVersion'] = $this->appInfo->identifyPHPVersion(); From 4e16e79b585e130f23b5f59ea08ac09d324666df Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:56:13 +0100 Subject: [PATCH 15/40] refactor: cleanup redundant PHPDocs --- .../src/Api/Resource/Contracts/Listable.php | 4 ---- .../core/src/Api/Resource/UserResource.php | 1 - .../Database/DatabaseMigrationRepository.php | 2 -- framework/core/src/Discussion/Discussion.php | 2 -- .../src/Discussion/DiscussionRepository.php | 2 -- .../src/Discussion/Search/FulltextFilter.php | 3 --- framework/core/src/Extend/Auth.php | 3 --- framework/core/src/Extend/Conditional.php | 7 ------- framework/core/src/Extend/Console.php | 2 -- framework/core/src/Extend/Csrf.php | 3 --- framework/core/src/Extend/ErrorHandling.php | 4 ---- framework/core/src/Extend/Event.php | 3 --- framework/core/src/Extend/Filesystem.php | 3 --- framework/core/src/Extend/Formatter.php | 8 -------- framework/core/src/Extend/Frontend.php | 10 ---------- framework/core/src/Extend/Mail.php | 1 - framework/core/src/Extend/Middleware.php | 5 ----- framework/core/src/Extend/Model.php | 11 ----------- framework/core/src/Extend/ModelPrivate.php | 2 -- framework/core/src/Extend/ModelUrl.php | 1 - framework/core/src/Extend/ModelVisibility.php | 4 ---- framework/core/src/Extend/Notification.php | 4 ---- framework/core/src/Extend/Policy.php | 2 -- framework/core/src/Extend/Post.php | 1 - framework/core/src/Extend/Routes.php | 11 ----------- framework/core/src/Extend/SearchDriver.php | 6 ------ framework/core/src/Extend/ServiceProvider.php | 1 - framework/core/src/Extend/Session.php | 1 - framework/core/src/Extend/Settings.php | 6 ------ framework/core/src/Extend/Theme.php | 5 ----- framework/core/src/Extend/ThrottleApi.php | 3 --- framework/core/src/Extend/User.php | 6 ------ framework/core/src/Extend/Validator.php | 2 -- framework/core/src/Extend/View.php | 6 ------ framework/core/src/Extension/Extension.php | 19 ------------------- framework/core/src/Formatter/Formatter.php | 3 --- .../core/src/Foundation/ContainerUtil.php | 2 -- .../ErrorHandling/HttpFormatter.php | 4 ---- .../src/Foundation/ErrorHandling/Registry.php | 3 --- .../src/Foundation/ErrorHandling/Reporter.php | 3 --- .../core/src/Foundation/InstalledSite.php | 1 - framework/core/src/Foundation/KnownError.php | 2 -- framework/core/src/Frontend/Assets.php | 3 --- .../Frontend/Compiler/RevisionCompiler.php | 1 - framework/core/src/Group/Group.php | 3 --- framework/core/src/Group/GroupRepository.php | 1 - framework/core/src/Http/Server.php | 1 - .../core/src/Notification/Notification.php | 3 --- framework/core/src/Queue/ExceptionHandler.php | 4 ---- framework/core/src/User/User.php | 5 ----- framework/core/src/helpers.php | 1 - 51 files changed, 194 deletions(-) diff --git a/framework/core/src/Api/Resource/Contracts/Listable.php b/framework/core/src/Api/Resource/Contracts/Listable.php index 956faf0879..0ff9ce5fad 100644 --- a/framework/core/src/Api/Resource/Contracts/Listable.php +++ b/framework/core/src/Api/Resource/Contracts/Listable.php @@ -21,15 +21,11 @@ interface Listable { /** * Create a query object for the current request. - * - * @param Context $context */ public function query(Context $context): object; /** * Get results from the given query. - * - * @param Context $context */ public function results(object $query, Context $context): iterable; diff --git a/framework/core/src/Api/Resource/UserResource.php b/framework/core/src/Api/Resource/UserResource.php index 2f9ac808db..1b98a639b5 100644 --- a/framework/core/src/Api/Resource/UserResource.php +++ b/framework/core/src/Api/Resource/UserResource.php @@ -231,7 +231,6 @@ public function fields(): array }) ->set(function (User $user, ?string $value, Context $context) { if ($value) { - /** @var RegistrationToken $token */ $token = RegistrationToken::validOrFail($value); $context->setParam('token', $token); diff --git a/framework/core/src/Database/DatabaseMigrationRepository.php b/framework/core/src/Database/DatabaseMigrationRepository.php index 3fb06fba3d..a47522cc0b 100644 --- a/framework/core/src/Database/DatabaseMigrationRepository.php +++ b/framework/core/src/Database/DatabaseMigrationRepository.php @@ -51,8 +51,6 @@ public function delete(string $file, ?string $extension = null): void /** * Create the migration repository data store. - * - * @return void */ public function createRepository(): void { diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 87d88ff6d2..27d74e19c9 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -283,8 +283,6 @@ public function comments(): HasMany /** * Query the discussion's participants (a list of unique users who have * posted in the discussion). - * - * @return Builder */ public function participants(): Builder { diff --git a/framework/core/src/Discussion/DiscussionRepository.php b/framework/core/src/Discussion/DiscussionRepository.php index 61cec343eb..8914d94e79 100644 --- a/framework/core/src/Discussion/DiscussionRepository.php +++ b/framework/core/src/Discussion/DiscussionRepository.php @@ -36,7 +36,6 @@ public function findOrFail(int|string $id, ?User $user = null): Discussion /** * Get a query containing the IDs of discussions which a user has read completely. * - * @param User $user * @return Builder */ public function getReadIdsQuery(User $user): Builder @@ -52,7 +51,6 @@ public function getReadIdsQuery(User $user): Builder * Scope a query to only include records that are visible to a user. * * @param Builder $query - * @param User|null $user * @return Builder */ protected function scopeVisibleTo(Builder $query, ?User $user = null): Builder diff --git a/framework/core/src/Discussion/Search/FulltextFilter.php b/framework/core/src/Discussion/Search/FulltextFilter.php index 0a890ca836..9320d466b0 100644 --- a/framework/core/src/Discussion/Search/FulltextFilter.php +++ b/framework/core/src/Discussion/Search/FulltextFilter.php @@ -42,7 +42,6 @@ public function search(SearchState $state, string $value): void protected function sqlite(DatabaseSearchState $state, string $value): void { - /** @var Builder $query */ $query = $state->getQuery(); $query->where(function (Builder $query) use ($state, $value) { @@ -63,7 +62,6 @@ protected function sqlite(DatabaseSearchState $state, string $value): void protected function mysql(DatabaseSearchState $state, string $value): void { - /** @var Builder $query */ $query = $state->getQuery(); // Replace all non-word characters with spaces. @@ -119,7 +117,6 @@ protected function pgsql(DatabaseSearchState $state, string $value): void { $searchConfig = $this->settings->get('pgsql_search_configuration'); - /** @var Builder $query */ $query = $state->getQuery(); $grammar = $query->getGrammar(); diff --git a/framework/core/src/Extend/Auth.php b/framework/core/src/Extend/Auth.php index 6e5e711240..27d7b78517 100644 --- a/framework/core/src/Extend/Auth.php +++ b/framework/core/src/Extend/Auth.php @@ -35,8 +35,6 @@ class Auth implements ExtenderInterface * password checkers can run. * - `false` if the given password is invalid, and no other checkers should be considered. * Evaluation will be immediately halted if any checkers return `false`. - * - * @return self */ public function addPasswordChecker(string $identifier, callable|string $callback): self { @@ -49,7 +47,6 @@ public function addPasswordChecker(string $identifier, callable|string $callback * Remove a password checker. * * @param string $identifier: The unique identifier of the password checker to remove. - * @return self */ public function removePasswordChecker(string $identifier): self { diff --git a/framework/core/src/Extend/Conditional.php b/framework/core/src/Extend/Conditional.php index 2e04855ced..4b1accf308 100644 --- a/framework/core/src/Extend/Conditional.php +++ b/framework/core/src/Extend/Conditional.php @@ -38,7 +38,6 @@ class Conditional implements ExtenderInterface * * @param string $extensionId The ID of the extension. * @param callable|string $extenders A callable returning an array of extenders, or an invokable class string. - * @return self */ public function whenExtensionEnabled(string $extensionId, callable|string $extenders): self { @@ -52,7 +51,6 @@ public function whenExtensionEnabled(string $extensionId, callable|string $exten * * @param string $extensionId The ID of the extension. * @param callable|string $extenders A callable returning an array of extenders, or an invokable class string. - * @return self */ public function whenExtensionDisabled(string $extensionId, callable|string $extenders): self { @@ -67,7 +65,6 @@ public function whenExtensionDisabled(string $extensionId, callable|string $exte * @param bool|callable $condition A boolean or callable that should return a boolean. * If this evaluates to true, the extenders will be applied. * @param callable|string $extenders A callable returning an array of extenders, or an invokable class string. - * @return self */ public function when(callable|bool $condition, callable|string $extenders): self { @@ -81,10 +78,6 @@ public function when(callable|bool $condition, callable|string $extenders): self /** * Iterates over the conditions and applies the associated extenders if the conditions are met. - * - * @param Container $container - * @param Extension|null $extension - * @return void */ public function extend(Container $container, ?Extension $extension = null): void { diff --git a/framework/core/src/Extend/Console.php b/framework/core/src/Extend/Console.php index e90f5e8ed5..5a7dc5986e 100644 --- a/framework/core/src/Extend/Console.php +++ b/framework/core/src/Extend/Console.php @@ -23,7 +23,6 @@ class Console implements ExtenderInterface * Add a command to the console. * * @param class-string $command: ::class attribute of command class, which must extend \Flarum\Console\AbstractCommand. - * @return self */ public function command(string $command): self { @@ -48,7 +47,6 @@ public function command(string $command): self * for more information on available methods and what they do. * * @param array $args An array of args to call the command with. - * @return self */ public function schedule(string $command, callable|string $callback, array $args = []): self { diff --git a/framework/core/src/Extend/Csrf.php b/framework/core/src/Extend/Csrf.php index 761b4cff8e..1d2a09218c 100644 --- a/framework/core/src/Extend/Csrf.php +++ b/framework/core/src/Extend/Csrf.php @@ -18,9 +18,6 @@ class Csrf implements ExtenderInterface /** * Exempt a named route from CSRF checks. - * - * @param string $routeName - * @return self */ public function exemptRoute(string $routeName): self { diff --git a/framework/core/src/Extend/ErrorHandling.php b/framework/core/src/Extend/ErrorHandling.php index f15f9e5ddb..d040a2a697 100644 --- a/framework/core/src/Extend/ErrorHandling.php +++ b/framework/core/src/Extend/ErrorHandling.php @@ -32,7 +32,6 @@ class ErrorHandling implements ExtenderInterface * * @param string $errorType: Type of the error. * @param int $httpStatus: The status code for this error. - * @return self */ public function status(string $errorType, int $httpStatus): self { @@ -52,7 +51,6 @@ public function status(string $errorType, int $httpStatus): self * * @param string $exceptionClass: The ::class attribute of the exception class. * @param string $errorType: Type of the error. - * @return self */ public function type(string $exceptionClass, string $errorType): self { @@ -77,7 +75,6 @@ public function type(string $exceptionClass, string $errorType): self * * @param string $exceptionClass: The ::class attribute of the exception class. * @param string $handlerClass: The ::class attribute of the handler class. - * @return self */ public function handler(string $exceptionClass, string $handlerClass): self { @@ -99,7 +96,6 @@ public function handler(string $exceptionClass, string $handlerClass): self * {@see Reporter} interface. * * @param class-string $reporterClass: The ::class attribute of the reporter class. - * @return self */ public function reporter(string $reporterClass): self { diff --git a/framework/core/src/Extend/Event.php b/framework/core/src/Extend/Event.php index 2c0c3e8786..f7f316e05a 100644 --- a/framework/core/src/Extend/Event.php +++ b/framework/core/src/Extend/Event.php @@ -29,8 +29,6 @@ class Event implements ExtenderInterface * - The ::class attribute of a class with a public `handle` method, which accepts an instance of the event as a parameter. * - An array, where the first argument is an object or class name, and the second argument is the method on the * first argument that should be executed as the listener. - * - * @return self */ public function listen(string $event, callable|string $listener): self { @@ -47,7 +45,6 @@ public function listen(string $event, callable|string $listener): self * @see https://laravel.com/docs/11.x/events#writing-event-subscribers * * @param string $subscriber: The ::class attribute of the subscriber class. - * @return self */ public function subscribe(string $subscriber): self { diff --git a/framework/core/src/Extend/Filesystem.php b/framework/core/src/Extend/Filesystem.php index 301c43c8b7..9fb50514b4 100644 --- a/framework/core/src/Extend/Filesystem.php +++ b/framework/core/src/Extend/Filesystem.php @@ -52,8 +52,6 @@ class Filesystem implements ExtenderInterface * ``` * * @see https://laravel.com/docs/11.x/filesystem#configuration - * - * @return self */ public function disk(string $name, callable|string $callback): self { @@ -68,7 +66,6 @@ public function disk(string $name, callable|string $callback): self * @param string $name: The name of the driver. * @param string $driverClass: The ::class attribute of the driver. * Driver must implement `\Flarum\Filesystem\DriverInterface`. - * @return self */ public function driver(string $name, string $driverClass): self { diff --git a/framework/core/src/Extend/Formatter.php b/framework/core/src/Extend/Formatter.php index 2c4855b976..e048da575f 100644 --- a/framework/core/src/Extend/Formatter.php +++ b/framework/core/src/Extend/Formatter.php @@ -36,8 +36,6 @@ class Formatter implements ExtenderInterface, LifecycleInterface * - \s9e\TextFormatter\Configurator $configurator * * The callable should return void. - * - * @return self */ public function configure(callable|string $callback): self { @@ -60,8 +58,6 @@ public function configure(callable|string $callback): self * * The callback should return: * - string $text: The text to be parsed. - * - * @return self */ public function parse(callable|string $callback): self { @@ -82,8 +78,6 @@ public function parse(callable|string $callback): self * * The callback should return: * - string $xml: The text to be unparsed. - * - * @return self */ public function unparse(callable|string $callback): self { @@ -106,8 +100,6 @@ public function unparse(callable|string $callback): self * * The callback should return: * - string $xml: The xml to be rendered. - * - * @return self */ public function render(callable|string $callback): self { diff --git a/framework/core/src/Extend/Frontend.php b/framework/core/src/Extend/Frontend.php index fb166f531a..e84ae9c7da 100644 --- a/framework/core/src/Extend/Frontend.php +++ b/framework/core/src/Extend/Frontend.php @@ -50,7 +50,6 @@ public function __construct( * Add a CSS file to load in the frontend. * * @param string $path: The path to the CSS file. - * @return self */ public function css(string $path): self { @@ -63,7 +62,6 @@ public function css(string $path): self * Add a JavaScript file to load in the frontend. * * @param string $path: The path to the JavaScript file. - * @return self */ public function js(string $path): self { @@ -98,8 +96,6 @@ public function jsDirectory(string $path): self * - \Psr\Http\Message\ServerRequestInterface $request * * The callable should return void. - * - * @return self */ public function route(string $path, string $name, callable|string|null $content = null): self { @@ -113,7 +109,6 @@ public function route(string $path, string $name, callable|string|null $content * This is necessary before overriding a route. * * @param string $name: The name of the route. - * @return self */ public function removeRoute(string $name): self { @@ -133,8 +128,6 @@ public function removeRoute(string $name): self * * The callable should return void. * @param int $priority: The priority of the content. Higher priorities are executed first. - * - * @return self */ public function content(callable|string|null $callback, int $priority = 0): self { @@ -165,9 +158,6 @@ public function content(callable|string|null $callback, int $priority = 0): self * ] * ]); * ``` - * - * @param callable|array $preloads - * @return self */ public function preloads(callable|array $preloads): self { diff --git a/framework/core/src/Extend/Mail.php b/framework/core/src/Extend/Mail.php index 99d556243a..3d87eb40d8 100644 --- a/framework/core/src/Extend/Mail.php +++ b/framework/core/src/Extend/Mail.php @@ -22,7 +22,6 @@ class Mail implements ExtenderInterface * * @param string $identifier: Identifier for mail driver. E.g. 'smtp' for SmtpDriver. * @param class-string $driver: ::class attribute of driver class, which must implement \Flarum\Mail\DriverInterface. - * @return self */ public function driver(string $identifier, string $driver): self { diff --git a/framework/core/src/Extend/Middleware.php b/framework/core/src/Extend/Middleware.php index 877cda0f90..578d99d07f 100644 --- a/framework/core/src/Extend/Middleware.php +++ b/framework/core/src/Extend/Middleware.php @@ -34,7 +34,6 @@ public function __construct( * * @param class-string $middleware: ::class attribute of the middleware class. * Must implement \Psr\Http\Server\MiddlewareInterface. - * @return self */ public function add(string $middleware): self { @@ -50,7 +49,6 @@ public function add(string $middleware): self * Or container binding name. * @param class-string $newMiddleware: ::class attribute of the middleware class. * Must implement \Psr\Http\Server\MiddlewareInterface. - * @return self */ public function replace(string $originalMiddleware, string $newMiddleware): self { @@ -63,7 +61,6 @@ public function replace(string $originalMiddleware, string $newMiddleware): self * Removes a middleware from the frontend. * * @param class-string $middleware: ::class attribute of the middleware class. - * @return self */ public function remove(string $middleware): self { @@ -79,7 +76,6 @@ public function remove(string $middleware): self * Or container binding name. * @param class-string $newMiddleware: ::class attribute of the middleware class. * Must implement \Psr\Http\Server\MiddlewareInterface. - * @return self */ public function insertBefore(string $originalMiddleware, string $newMiddleware): self { @@ -95,7 +91,6 @@ public function insertBefore(string $originalMiddleware, string $newMiddleware): * Or container binding name. * @param class-string $newMiddleware: ::class attribute of the middleware class. * Must implement \Psr\Http\Server\MiddlewareInterface. - * @return self */ public function insertAfter(string $originalMiddleware, string $newMiddleware): self { diff --git a/framework/core/src/Extend/Model.php b/framework/core/src/Extend/Model.php index 3197ea726b..b35dba5d70 100644 --- a/framework/core/src/Extend/Model.php +++ b/framework/core/src/Extend/Model.php @@ -38,7 +38,6 @@ public function __construct( * * @param string $attribute: The new attribute name. * @param string $cast: The cast type. See https://laravel.com/docs/11.x/eloquent-mutators#attribute-casting - * @return self */ public function cast(string $attribute, string $cast): self { @@ -51,10 +50,6 @@ public function cast(string $attribute, string $cast): self * Add a default value for a given attribute, which can be an explicit value, a closure, * or an instance of an invokable class. Unlike with some other extenders, * it CANNOT be the `::class` attribute of an invokable class. - * - * @param string $attribute - * @param mixed $value - * @return self */ public function default(string $attribute, mixed $value): self { @@ -74,7 +69,6 @@ public function default(string $attribute, mixed $value): self * @param string $related: The ::class attribute of the model, which should extend \Flarum\Database\AbstractModel. * @param string|null $foreignKey: The foreign key attribute of the parent model. * @param string|null $ownerKey: The primary key attribute of the parent model. - * @return self */ public function belongsTo(string $name, string $related, ?string $foreignKey = null, ?string $ownerKey = null): self { @@ -97,7 +91,6 @@ public function belongsTo(string $name, string $related, ?string $foreignKey = n * @param string|null $relatedPivotKey: The associated key attribute of the relation. * @param string|null $parentKey: The key name of the parent model. * @param string|null $relatedKey: The key name of the related model. - * @return self */ public function belongsToMany( string $name, @@ -124,7 +117,6 @@ public function belongsToMany( * @param string $related: The ::class attribute of the model, which should extend \Flarum\Database\AbstractModel. * @param string|null $foreignKey: The foreign key attribute of the parent model. * @param string|null $localKey: The primary key attribute of the parent model. - * @return self */ public function hasOne(string $name, string $related, ?string $foreignKey = null, ?string $localKey = null): self { @@ -144,7 +136,6 @@ public function hasOne(string $name, string $related, ?string $foreignKey = null * @param string $related: The ::class attribute of the model, which should extend \Flarum\Database\AbstractModel. * @param string|null $foreignKey: The foreign key attribute of the parent model. * @param string|null $localKey: The primary key attribute of the parent model. - * @return self */ public function hasMany(string $name, string $related, ?string $foreignKey = null, ?string $localKey = null): self { @@ -167,8 +158,6 @@ public function hasMany(string $name, string $related, ?string $foreignKey = nul * The callable should return: * - $relationship: A Laravel Relationship object. See relevant methods of models * like \Flarum\User\User for examples of how relationships should be returned. - * - * @return self */ public function relationship(string $name, callable|string $callback): self { diff --git a/framework/core/src/Extend/ModelPrivate.php b/framework/core/src/Extend/ModelPrivate.php index 3b63e12b79..7db1e462f2 100644 --- a/framework/core/src/Extend/ModelPrivate.php +++ b/framework/core/src/Extend/ModelPrivate.php @@ -55,8 +55,6 @@ public function __construct( * - \Flarum\Database\AbstractModel $instance: An instance of the model. * * It should return `true` if the model instance should be made private. - * - * @return self */ public function checker(callable|string $callback): self { diff --git a/framework/core/src/Extend/ModelUrl.php b/framework/core/src/Extend/ModelUrl.php index 1560242c44..6bccedfc11 100644 --- a/framework/core/src/Extend/ModelUrl.php +++ b/framework/core/src/Extend/ModelUrl.php @@ -32,7 +32,6 @@ public function __construct( * * @param string $identifier: Identifier for slug driver. * @param string $driver: ::class attribute of driver class, which must implement Flarum\Http\SlugDriverInterface. - * @return self */ public function addSlugDriver(string $identifier, string $driver): self { diff --git a/framework/core/src/Extend/ModelVisibility.php b/framework/core/src/Extend/ModelVisibility.php index 21bd3e19e2..f9b0af918e 100644 --- a/framework/core/src/Extend/ModelVisibility.php +++ b/framework/core/src/Extend/ModelVisibility.php @@ -61,8 +61,6 @@ public function __construct( * - \Illuminate\Database\Eloquent\Builder $query * * The callback should return void. - * - * @return self */ public function scope(callable|string $callback, string $ability = 'view'): self { @@ -82,8 +80,6 @@ public function scope(callable|string $callback, string $ability = 'view'): self * - string $ability * * The callback should return void. - * - * @return self */ public function scopeAll(callable|string $callback): self { diff --git a/framework/core/src/Extend/Notification.php b/framework/core/src/Extend/Notification.php index 4386fe1d51..1234f87044 100644 --- a/framework/core/src/Extend/Notification.php +++ b/framework/core/src/Extend/Notification.php @@ -28,7 +28,6 @@ class Notification implements ExtenderInterface * This blueprint should implement \Flarum\Notification\Blueprint\BlueprintInterface. * @param string[] $driversEnabledByDefault: The names of the drivers enabled by default for this notification type. * (example: alert, email). - * @return self */ public function type(string $blueprint, array $driversEnabledByDefault = []): self { @@ -42,7 +41,6 @@ public function type(string $blueprint, array $driversEnabledByDefault = []): se * @param class-string $driver: The ::class attribute of the driver class. * This driver should implement \Flarum\Notification\Driver\NotificationDriverInterface. * @param string[] $typesEnabledByDefault: The names of blueprint classes of types enabled by default for this driver. - * @return self */ public function driver(string $driverName, string $driver, array $typesEnabledByDefault = []): self { @@ -61,8 +59,6 @@ public function driver(string $driverName, string $driver, array $typesEnabledBy * * The callable should return an array of recipients. * - \Flarum\User\User[] $newRecipients - * - * @return self */ public function beforeSending(callable|string $callback): self { diff --git a/framework/core/src/Extend/Policy.php b/framework/core/src/Extend/Policy.php index ff1ab6c891..dae4687de5 100644 --- a/framework/core/src/Extend/Policy.php +++ b/framework/core/src/Extend/Policy.php @@ -22,7 +22,6 @@ class Policy implements ExtenderInterface * Add a custom policy for when an ability check is ran without a model instance. * * @param class-string $policy: ::class attribute of policy class, which must extend \Flarum\User\Access\AbstractPolicy - * @return self */ public function globalPolicy(string $policy): self { @@ -37,7 +36,6 @@ public function globalPolicy(string $policy): self * @param string $modelClass: The ::class attribute of the model you are applying policies to. * This model should extend from \Flarum\Database\AbstractModel. * @param string $policy: ::class attribute of policy class, which must extend Flarum\User\Access\AbstractPolicy - * @return self */ public function modelPolicy(string $modelClass, string $policy): self { diff --git a/framework/core/src/Extend/Post.php b/framework/core/src/Extend/Post.php index 27282a4d23..775aec5e97 100644 --- a/framework/core/src/Extend/Post.php +++ b/framework/core/src/Extend/Post.php @@ -22,7 +22,6 @@ class Post implements ExtenderInterface * such as those that appear when a discussion is renamed. * * @param string $postType: The ::class attribute of the custom Post type that is being added. - * @return self */ public function type(string $postType): self { diff --git a/framework/core/src/Extend/Routes.php b/framework/core/src/Extend/Routes.php index a2f7192924..cbe1b2824a 100644 --- a/framework/core/src/Extend/Routes.php +++ b/framework/core/src/Extend/Routes.php @@ -43,8 +43,6 @@ public function __construct( * * The handler should return: * - \Psr\Http\Message\ResponseInterface $response - * - * @return self */ public function get(string $path, string $name, callable|string $handler): self { @@ -66,8 +64,6 @@ public function get(string $path, string $name, callable|string $handler): self * * The handler should return: * - \Psr\Http\Message\ResponseInterface $response - * - * @return self */ public function post(string $path, string $name, callable|string $handler): self { @@ -89,8 +85,6 @@ public function post(string $path, string $name, callable|string $handler): self * * The handler should return: * - \Psr\Http\Message\ResponseInterface $response - * - * @return self */ public function put(string $path, string $name, callable|string $handler): self { @@ -112,8 +106,6 @@ public function put(string $path, string $name, callable|string $handler): self * * The handler should return: * - \Psr\Http\Message\ResponseInterface $response - * - * @return self */ public function patch(string $path, string $name, callable|string $handler): self { @@ -135,8 +127,6 @@ public function patch(string $path, string $name, callable|string $handler): sel * * The handler should return: * - \Psr\Http\Message\ResponseInterface $response - * - * @return self */ public function delete(string $path, string $name, callable|string $handler): self { @@ -160,7 +150,6 @@ private function route(string $httpMethod, string $path, string $name, callable| * Necessary before overriding a route. * * @param string $name: The name of the route. - * @return self */ public function remove(string $name): self { diff --git a/framework/core/src/Extend/SearchDriver.php b/framework/core/src/Extend/SearchDriver.php index 4e1e545ac9..f0ee325277 100644 --- a/framework/core/src/Extend/SearchDriver.php +++ b/framework/core/src/Extend/SearchDriver.php @@ -44,7 +44,6 @@ public function __construct( * @param class-string $searcherClass : The class of the Searcher for this model * This searcher must implement \Flarum\Search\SearcherInterface. * Or extend \Flarum\Search\Database\AbstractSearcher if using the default driver. - * @return self */ public function addSearcher(string $modelClass, string $searcherClass): self { @@ -61,7 +60,6 @@ public function addSearcher(string $modelClass, string $searcherClass): self * Or extend \Flarum\Search\Database\AbstractSearcher if using the default driver. * @param class-string $filterClass: The ::class attribute of the filter you are adding. * This filter must implement \Flarum\Search\FilterInterface - * @return self */ public function addFilter(string $searcherClass, string $filterClass): self { @@ -79,7 +77,6 @@ public function addFilter(string $searcherClass, string $filterClass): self * @param class-string $replaceFilterClass : The ::class attribute of the filter you are replacing. * @param class-string $filterClass : The ::class attribute of the filter you are adding. * This filter must implement \Flarum\Search\FilterInterface - * @return self */ public function replaceFilter(string $searcherClass, string $replaceFilterClass, string $filterClass): self { @@ -99,7 +96,6 @@ public function replaceFilter(string $searcherClass, string $replaceFilterClass, * Or extend \Flarum\Search\Database\AbstractSearcher if using the default driver. * @param class-string $fulltextClass: The ::class attribute of the full test filter you are adding. * This filter must implement \Flarum\Search\FilterInterface - * @return self */ public function setFulltext(string $searcherClass, string $fulltextClass): self { @@ -121,8 +117,6 @@ public function setFulltext(string $searcherClass, string $fulltextClass): self * - \Flarum\Query\QueryCriteria $criteria * * The callback should return void. - * - * @return self */ public function addMutator(string $searcherClass, callable|string $callback): self { diff --git a/framework/core/src/Extend/ServiceProvider.php b/framework/core/src/Extend/ServiceProvider.php index 58f98781c4..3f24505197 100644 --- a/framework/core/src/Extend/ServiceProvider.php +++ b/framework/core/src/Extend/ServiceProvider.php @@ -25,7 +25,6 @@ class ServiceProvider implements ExtenderInterface * @see https://docs.flarum.org/extend/service-provider/ * * @param class-string $serviceProviderClass The ::class attribute of the service provider class. - * @return self */ public function register(string $serviceProviderClass): self { diff --git a/framework/core/src/Extend/Session.php b/framework/core/src/Extend/Session.php index a44971571e..7bb738e08f 100644 --- a/framework/core/src/Extend/Session.php +++ b/framework/core/src/Extend/Session.php @@ -25,7 +25,6 @@ class Session implements ExtenderInterface * @param string $name: The name of the driver. * @param class-string $driverClass: The ::class attribute of the driver. * Driver must implement `\Flarum\User\SessionDriverInterface`. - * @return self */ public function driver(string $name, string $driverClass): self { diff --git a/framework/core/src/Extend/Settings.php b/framework/core/src/Extend/Settings.php index 68a9555d28..0f49f046c5 100644 --- a/framework/core/src/Extend/Settings.php +++ b/framework/core/src/Extend/Settings.php @@ -40,8 +40,6 @@ class Settings implements ExtenderInterface * * The callable should return: * - mixed $value: The modified value. - * - * @return self */ public function serializeToForum(string $attributeName, string $key, callable|string|null $callback = null): self { @@ -56,7 +54,6 @@ public function serializeToForum(string $attributeName, string $key, callable|st * * @param string $key: The setting key, must be unique. Namespace it with the extension ID (example: 'my-extension-id.setting_key'). * @param mixed $value: The setting value. - * @return self */ public function default(string $key, mixed $value): self { @@ -91,8 +88,6 @@ public function resetWhen(string $key, callable|string $callback): self * * The callable should return: * - mixed $value: The modified value. - * - * @return self */ public function registerLessConfigVar(string $configName, string $key, callable|string|null $callback = null): self { @@ -105,7 +100,6 @@ public function registerLessConfigVar(string $configName, string $key, callable| * Register a setting that should trigger JS cache clear when saved. * * @param string $setting: The key of the setting. - * @return self */ public function resetJsCacheFor(string $setting): self { diff --git a/framework/core/src/Extend/Theme.php b/framework/core/src/Extend/Theme.php index f878e42b1d..de0a40d5eb 100644 --- a/framework/core/src/Extend/Theme.php +++ b/framework/core/src/Extend/Theme.php @@ -29,7 +29,6 @@ class Theme implements ExtenderInterface * @param string $file : Relative path of the file to override, for example: `forum/Hero.less` * @param string $newFilePath : Absolute path of the new file. * @param string|null $extensionId : If overriding an extension file, specify its ID, for example: `flarum-tags`. - * @return self */ public function overrideLessImport(string $file, string $newFilePath, ?string $extensionId = null): self { @@ -46,7 +45,6 @@ public function overrideLessImport(string $file, string $newFilePath, ?string $e * @param string $file : Name of the file to override, for example: `admin.less` * @param string $newFilePath : Absolute path of the new file. * @param string|null $extensionId : If overriding an extension file, specify its ID, for example: `flarum-tags`. - * @return self */ public function overrideFileSource(string $file, string $newFilePath, ?string $extensionId = null): self { @@ -72,7 +70,6 @@ public function overrideFileSource(string $file, string $newFilePath, ?string $e * * @param string $functionName Name of the function identifier. * @param callable $callable The PHP function to run when the Less function is called. - * @return self */ public function addCustomLessFunction(string $functionName, callable $callable): self { @@ -126,8 +123,6 @@ public function addCustomLessFunction(string $functionName, callable $callable): * * @param string $variableName Name of the variable identifier. * @param callable $value The PHP function to run, which returns the value for the variable. - * - * @return self */ public function addCustomLessVariable(string $variableName, callable $value): self { diff --git a/framework/core/src/Extend/ThrottleApi.php b/framework/core/src/Extend/ThrottleApi.php index 006b3db8d8..3a1ee7ee7f 100644 --- a/framework/core/src/Extend/ThrottleApi.php +++ b/framework/core/src/Extend/ThrottleApi.php @@ -36,8 +36,6 @@ class ThrottleApi implements ExtenderInterface * - `false`: This marks the request as NOT to be throttled. It overrides all other throttlers * - `true`: This marks the request as to be throttled. * All other outputs will be ignored. - * - * @return self */ public function set(string $name, callable|string $callback): self { @@ -50,7 +48,6 @@ public function set(string $name, callable|string $callback): self * Remove a throttler registered with this name. * * @param string $name: The name of the throttler to remove. - * @return self */ public function remove(string $name): self { diff --git a/framework/core/src/Extend/User.php b/framework/core/src/Extend/User.php index 1b76322f59..e88785a7ec 100644 --- a/framework/core/src/Extend/User.php +++ b/framework/core/src/Extend/User.php @@ -25,7 +25,6 @@ class User implements ExtenderInterface * * @param string $identifier: Identifier for display name driver. E.g. 'username' for UserNameDriver * @param class-string $driver: ::class attribute of driver class, which must implement Flarum\User\DisplayName\DriverInterface - * @return self */ public function displayNameDriver(string $identifier, string $driver): self { @@ -47,8 +46,6 @@ public function displayNameDriver(string $identifier, string $driver): self * * The callable should return: * - array $groupIds: an array of ids for the groups the user belongs to. - * - * @return self */ public function permissionGroups(callable|string $callback): self { @@ -60,10 +57,7 @@ public function permissionGroups(callable|string $callback): self /** * Register a new user preference. * - * @param string $key - * @param callable|null $transformer * @param mixed|null $default - * @return self */ public function registerPreference(string $key, ?callable $transformer = null, mixed $default = null): self { diff --git a/framework/core/src/Extend/Validator.php b/framework/core/src/Extend/Validator.php index a845404986..86bb9d8e60 100644 --- a/framework/core/src/Extend/Validator.php +++ b/framework/core/src/Extend/Validator.php @@ -38,8 +38,6 @@ public function __construct( * - \Illuminate\Validation\Validator $validator: The Laravel validator instance * * The callback should return void. - * - * @return self */ public function configure(callable|string $callback): self { diff --git a/framework/core/src/Extend/View.php b/framework/core/src/Extend/View.php index 71c9f5e971..1130d52fef 100644 --- a/framework/core/src/Extend/View.php +++ b/framework/core/src/Extend/View.php @@ -37,7 +37,6 @@ class View implements ExtenderInterface, LifecycleInterface * @param string $namespace: The name of the namespace. * @param string|string[] $hints: This is a path (or an array of paths) to the folder(s) * where view files are stored, relative to the extend.php file. - * @return self */ public function namespace(string $namespace, array|string $hints): self { @@ -55,7 +54,6 @@ public function namespace(string $namespace, array|string $hints): self * @param string $namespace: The name of the namespace. * @param string|string[] $hints: This is a path (or an array of paths) to the folder(s) * where view files are stored, relative to the `extend.php` file. - * @return self */ public function extendNamespace(string $namespace, array|string $hints): self { @@ -77,8 +75,6 @@ public function extend(Container $container, ?Extension $extension = null): void } /** - * @param Container $container - * @param Extension $extension * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function onEnable(Container $container, Extension $extension): void @@ -88,8 +84,6 @@ public function onEnable(Container $container, Extension $extension): void } /** - * @param Container $container - * @param Extension $extension * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function onDisable(Container $container, Extension $extension): void diff --git a/framework/core/src/Extension/Extension.php b/framework/core/src/Extension/Extension.php index ef4d50ed80..b7188a6301 100644 --- a/framework/core/src/Extension/Extension.php +++ b/framework/core/src/Extension/Extension.php @@ -144,9 +144,6 @@ public function setInstalled(bool $installed): static return $this; } - /** - * @return bool - */ public function isInstalled(): bool { return $this->installed; @@ -263,25 +260,17 @@ public function disable(Container $container): void /** * The raw path of the directory under extensions. - * - * @return string */ public function getId(): string { return $this->id; } - /** - * @return string - */ public function getTitle(): string { return $this->composerJsonAttribute('extra.flarum-extension.title'); } - /** - * @return string - */ public function getPath(): string { return $this->path; @@ -289,8 +278,6 @@ public function getPath(): string /** * The IDs of all Flarum extensions that this extension depends on. - * - * @return array */ public function getExtensionDependencyIds(): array { @@ -300,8 +287,6 @@ public function getExtensionDependencyIds(): array /** * The IDs of all Flarum extensions that this extension should be booted after * if enabled. - * - * @return array */ public function getOptionalDependencyIds(): array { @@ -447,8 +432,6 @@ public function migrate(Migrator $migrator, string $direction = 'up'): ?int /** * Generates an array result for the object. - * - * @return array */ public function toArray(): array { @@ -467,8 +450,6 @@ public function toArray(): array /** * Gets the rendered contents of the extension README file as a HTML string. - * - * @return string|null */ public function getReadme(): ?string { diff --git a/framework/core/src/Formatter/Formatter.php b/framework/core/src/Formatter/Formatter.php index 9434019fd1..51019bfe47 100644 --- a/framework/core/src/Formatter/Formatter.php +++ b/framework/core/src/Formatter/Formatter.php @@ -207,9 +207,6 @@ protected function configureDefaultsOnLinks(string $xml): string /** * Converts a plain text string (with or without Markdown) to it's HTML equivalent. - * - * @param ?string $content - * @return string */ public function convert(?string $content): string { diff --git a/framework/core/src/Foundation/ContainerUtil.php b/framework/core/src/Foundation/ContainerUtil.php index b0ce825dce..9e1aa04ed9 100644 --- a/framework/core/src/Foundation/ContainerUtil.php +++ b/framework/core/src/Foundation/ContainerUtil.php @@ -17,9 +17,7 @@ class ContainerUtil * Wraps a callback so that string-based invokable classes get resolved only when actually used. * * @param callable|class-string $callback : A callable, global function, or a ::class attribute of an invokable class - * @param Container $container * - * @return callable * @internal Backwards compatibility not guaranteed. */ public static function wrapCallback(callable|string $callback, Container $container): callable diff --git a/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php b/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php index 812c446552..0d4a2641d8 100644 --- a/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/HttpFormatter.php @@ -20,10 +20,6 @@ interface HttpFormatter * This method receives the error that was caught by Flarum's error handling * stack, along with the current HTTP request instance. It should return an * HTTP response that explains or represents what went wrong. - * - * @param HandledError $error - * @param Request $request - * @return Response */ public function format(HandledError $error, Request $request): Response; } diff --git a/framework/core/src/Foundation/ErrorHandling/Registry.php b/framework/core/src/Foundation/ErrorHandling/Registry.php index 74a8bb0831..b8a8290df1 100644 --- a/framework/core/src/Foundation/ErrorHandling/Registry.php +++ b/framework/core/src/Foundation/ErrorHandling/Registry.php @@ -36,9 +36,6 @@ public function __construct( * of {@see HandledError}. * * Even for unknown exceptions, a generic fallback will always be returned. - * - * @param Throwable $error - * @return HandledError */ public function handle(Throwable $error): HandledError { diff --git a/framework/core/src/Foundation/ErrorHandling/Reporter.php b/framework/core/src/Foundation/ErrorHandling/Reporter.php index 591c6df702..d0e132072a 100644 --- a/framework/core/src/Foundation/ErrorHandling/Reporter.php +++ b/framework/core/src/Foundation/ErrorHandling/Reporter.php @@ -15,9 +15,6 @@ interface Reporter { /** * Report an error that Flarum was not able to handle to a backend. - * - * @param Throwable $error - * @return void */ public function report(Throwable $error): void; } diff --git a/framework/core/src/Foundation/InstalledSite.php b/framework/core/src/Foundation/InstalledSite.php index 871a2bca0a..e6a020e6d3 100644 --- a/framework/core/src/Foundation/InstalledSite.php +++ b/framework/core/src/Foundation/InstalledSite.php @@ -78,7 +78,6 @@ public function bootApp(): AppInterface /** * @param ExtenderInterface[] $extenders - * @return InstalledSite */ public function extendWith(array $extenders): self { diff --git a/framework/core/src/Foundation/KnownError.php b/framework/core/src/Foundation/KnownError.php index 12c89b8183..4d36376e74 100644 --- a/framework/core/src/Foundation/KnownError.php +++ b/framework/core/src/Foundation/KnownError.php @@ -32,8 +32,6 @@ interface KnownError * Different exception classes are allowed to return the same status code, * e.g. when they have similar semantic meaning to the end user, but are * thrown by different subsystems. - * - * @return string */ public function getType(): string; } diff --git a/framework/core/src/Frontend/Assets.php b/framework/core/src/Frontend/Assets.php index b479096dd5..5a8464cbbc 100644 --- a/framework/core/src/Frontend/Assets.php +++ b/framework/core/src/Frontend/Assets.php @@ -23,9 +23,6 @@ */ class Assets { - /** - * @var array - */ public array $sources = [ 'js' => [], 'css' => [], diff --git a/framework/core/src/Frontend/Compiler/RevisionCompiler.php b/framework/core/src/Frontend/Compiler/RevisionCompiler.php index 4cd5aad5fc..abfe5f7db4 100644 --- a/framework/core/src/Frontend/Compiler/RevisionCompiler.php +++ b/framework/core/src/Frontend/Compiler/RevisionCompiler.php @@ -93,7 +93,6 @@ public function getUrl(): ?string } /** - * @param string $file * @param SourceInterface[] $sources * @return bool true if the file was written, false if there was nothing to write */ diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index c2fd48ae1e..963c7177d4 100644 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -86,9 +86,6 @@ public function users(): BelongsToMany return $this->belongsToMany(User::class); } - /** - * @return HasMany - */ public function permissions(): HasMany { return $this->hasMany(Permission::class); diff --git a/framework/core/src/Group/GroupRepository.php b/framework/core/src/Group/GroupRepository.php index 1a6bc4b515..79fd4e3eee 100644 --- a/framework/core/src/Group/GroupRepository.php +++ b/framework/core/src/Group/GroupRepository.php @@ -44,7 +44,6 @@ public function queryVisibleTo(?User $actor = null): Builder * Scope a query to only include records that are visible to a user. * * @param Builder $query - * @param User|null $actor * @return Builder */ protected function scopeVisibleTo(Builder $query, ?User $actor = null): Builder diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index 959f9d2af7..5616dc9e65 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -76,7 +76,6 @@ private function safelyBootAndGetHandler() // @phpstan-ignore-line * There is always a risk for this to fail, * for example if the container bindings aren't present * or if there is a filesystem error. - * @param Throwable $error * @throws Throwable */ private function cleanBootExceptionLog(Throwable $error): void diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index 3819efe71d..3cb66047c1 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -93,9 +93,6 @@ public function fromUser(): BelongsTo return $this->belongsTo(User::class, 'from_user_id'); } - /** - * @return MorphTo - */ public function subject(): MorphTo { return $this->morphTo('subject', 'subjectModel'); diff --git a/framework/core/src/Queue/ExceptionHandler.php b/framework/core/src/Queue/ExceptionHandler.php index 3dc23f0229..946b560d49 100644 --- a/framework/core/src/Queue/ExceptionHandler.php +++ b/framework/core/src/Queue/ExceptionHandler.php @@ -23,7 +23,6 @@ public function __construct( /** * Report or log an exception. * - * @param Throwable $e * @return void */ public function report(Throwable $e) @@ -35,7 +34,6 @@ public function report(Throwable $e) * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request - * @param Throwable $e * @return void */ public function render($request, Throwable $e) /** @phpstan-ignore-line */ @@ -47,7 +45,6 @@ public function render($request, Throwable $e) /** @phpstan-ignore-line */ * Render an exception to the console. * * @param \Symfony\Component\Console\Output\OutputInterface $output - * @param Throwable $e * @return void */ public function renderForConsole($output, Throwable $e) @@ -58,7 +55,6 @@ public function renderForConsole($output, Throwable $e) /** * Determine if the exception should be reported. * - * @param Throwable $e * @return bool */ public function shouldReport(Throwable $e) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index e5ab88a328..87a4ca3fff 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -351,9 +351,6 @@ protected function unreadNotifications(): HasMany ->whereSubjectVisibleTo($this); } - /** - * @return Collection - */ protected function getUnreadNotifications(): Collection { return $this->unreadNotifications()->get(); @@ -573,8 +570,6 @@ public function passwordTokens(): HasMany /** * Define the relationship with the permissions of all the groups that * the user is in. - * - * @return Builder */ public function permissions(): Builder { diff --git a/framework/core/src/helpers.php b/framework/core/src/helpers.php index 4fcef6e84a..94bda5f0f5 100644 --- a/framework/core/src/helpers.php +++ b/framework/core/src/helpers.php @@ -17,7 +17,6 @@ * * @template T * @param string|class-string $name - * @param array $parameters * @return T|mixed */ function resolve(string $name, array $parameters = []) From c88c6a5b1f359ac14a9231c942cc293f90fb599b Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:58:19 +0100 Subject: [PATCH 16/40] refactor: use $this instead of parent:: --- framework/core/src/User/SessionManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/User/SessionManager.php b/framework/core/src/User/SessionManager.php index 101ecc37d1..bbfb9f8383 100644 --- a/framework/core/src/User/SessionManager.php +++ b/framework/core/src/User/SessionManager.php @@ -30,10 +30,10 @@ public function handler(): SessionHandlerInterface $driverName = Arr::get($config, 'session.driver'); try { - $driverInstance = parent::driver($driverName); + $driverInstance = $this->driver($driverName); } catch (InvalidArgumentException) { $defaultDriverName = $this->getDefaultDriver(); - $driverInstance = parent::driver($defaultDriverName); + $driverInstance = $this->driver($defaultDriverName); // But we will log a critical error to the webmaster. $this->container->make(LoggerInterface::class)->critical( From 441d7cf42fe25d13406cad3ac4eb0368c379d839 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:59:43 +0100 Subject: [PATCH 17/40] refactor: drop unnecessary null coalescing The method can either return `int` or `null`. There is no need to coalesce `null` into `null`. --- .../core/src/Api/Endpoint/Concerns/ExtractsListingParams.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php b/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php index 046d010461..e3d483c817 100644 --- a/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php +++ b/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php @@ -103,7 +103,7 @@ public function defaultExtracts(Context $context): array return [ 'filter' => RequestUtil::extractFilter($context->request), 'sort' => RequestUtil::extractSort($context->request, $this->defaultSort, $this->getAvailableSorts($context)), - 'limit' => $limit = (RequestUtil::extractLimit($context->request, $this->limit, $this->maxLimit) ?? null), + 'limit' => $limit = (RequestUtil::extractLimit($context->request, $this->limit, $this->maxLimit)), 'offset' => RequestUtil::extractOffset($context->request, $limit), ]; } From faab6deff389e3b35b9867f50783df61a65afcc9 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:00:01 +0100 Subject: [PATCH 18/40] refactor: merge unset calls --- framework/core/src/Forum/Content/Discussion.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/core/src/Forum/Content/Discussion.php b/framework/core/src/Forum/Content/Discussion.php index abcd23a806..8d5779627d 100644 --- a/framework/core/src/Forum/Content/Discussion.php +++ b/framework/core/src/Forum/Content/Discussion.php @@ -43,8 +43,7 @@ public function __invoke(Document $document, Request $request): Document $url = function ($newQueryParams) use ($queryParams, $apiDocument) { $newQueryParams = array_merge($queryParams, $newQueryParams); - unset($newQueryParams['id']); - unset($newQueryParams['near']); + unset($newQueryParams['id'], $newQueryParams['near']); if (Arr::get($newQueryParams, 'page') == 1) { unset($newQueryParams['page']); From e45718b9995a556509645510de640a4ce1914e46 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:00:34 +0100 Subject: [PATCH 19/40] refactor: add missing access modifiers No modifier = `public`, therefore I've added `public`. --- framework/core/src/Api/Middleware/FakeHttpMethods.php | 2 +- framework/core/src/Extension/Extension.php | 2 +- framework/core/src/Foundation/Application.php | 2 +- .../core/src/Foundation/ErrorHandling/ViewFormatter.php | 2 +- .../core/src/Foundation/HighMaintenanceModeHandler.php | 2 +- framework/core/src/Frontend/Compiler/FileVersioner.php | 2 +- framework/core/src/Frontend/Compiler/RevisionCompiler.php | 2 +- framework/core/src/Group/Group.php | 8 ++++---- .../core/src/Http/Middleware/AuthenticateWithHeader.php | 2 +- framework/core/src/Http/Rememberer.php | 2 +- framework/core/src/Locale/Translator.php | 2 +- framework/core/src/Notification/UnsubscribeToken.php | 2 +- framework/core/src/User/LoginProvider.php | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/framework/core/src/Api/Middleware/FakeHttpMethods.php b/framework/core/src/Api/Middleware/FakeHttpMethods.php index 489ae3e53d..bb46419b2c 100644 --- a/framework/core/src/Api/Middleware/FakeHttpMethods.php +++ b/framework/core/src/Api/Middleware/FakeHttpMethods.php @@ -16,7 +16,7 @@ class FakeHttpMethods implements Middleware { - const HEADER_NAME = 'x-http-method-override'; + public const HEADER_NAME = 'x-http-method-override'; public function process(Request $request, Handler $handler): Response { diff --git a/framework/core/src/Extension/Extension.php b/framework/core/src/Extension/Extension.php index b7188a6301..70e8b34860 100644 --- a/framework/core/src/Extension/Extension.php +++ b/framework/core/src/Extension/Extension.php @@ -44,7 +44,7 @@ */ class Extension implements Arrayable { - const LOGO_MIMETYPES = [ + public const LOGO_MIMETYPES = [ 'svg' => 'image/svg+xml', 'png' => 'image/png', 'jpeg' => 'image/jpeg', diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index 2c46ddb555..fccc664148 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -25,7 +25,7 @@ class Application extends IlluminateContainer implements LaravelApplication * * @var string */ - const VERSION = '2.0.0-beta.2'; + public const VERSION = '2.0.0-beta.2'; protected bool $booted = false; diff --git a/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php b/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php index 49dd52a5d5..5b496e1ea7 100644 --- a/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php @@ -29,7 +29,7 @@ */ class ViewFormatter implements HttpFormatter { - const ERRORS_WITH_VIEWS = ['csrf_token_mismatch', 'not_found', 'maintenance']; + public const ERRORS_WITH_VIEWS = ['csrf_token_mismatch', 'not_found', 'maintenance']; public function __construct( protected ViewFactory $view, diff --git a/framework/core/src/Foundation/HighMaintenanceModeHandler.php b/framework/core/src/Foundation/HighMaintenanceModeHandler.php index b45048e14d..1e065275ef 100644 --- a/framework/core/src/Foundation/HighMaintenanceModeHandler.php +++ b/framework/core/src/Foundation/HighMaintenanceModeHandler.php @@ -18,7 +18,7 @@ class HighMaintenanceModeHandler implements RequestHandlerInterface { - const MESSAGE = 'Currently down for maintenance. Please come back later.'; + public const MESSAGE = 'Currently down for maintenance. Please come back later.'; /** * Handle the request and return a response. diff --git a/framework/core/src/Frontend/Compiler/FileVersioner.php b/framework/core/src/Frontend/Compiler/FileVersioner.php index c600c64261..f4efd5c53d 100644 --- a/framework/core/src/Frontend/Compiler/FileVersioner.php +++ b/framework/core/src/Frontend/Compiler/FileVersioner.php @@ -14,7 +14,7 @@ class FileVersioner implements VersionerInterface { - const REV_MANIFEST = 'rev-manifest.json'; + public const REV_MANIFEST = 'rev-manifest.json'; public function __construct( protected Filesystem $filesystem diff --git a/framework/core/src/Frontend/Compiler/RevisionCompiler.php b/framework/core/src/Frontend/Compiler/RevisionCompiler.php index abfe5f7db4..58b3269c68 100644 --- a/framework/core/src/Frontend/Compiler/RevisionCompiler.php +++ b/framework/core/src/Frontend/Compiler/RevisionCompiler.php @@ -23,7 +23,7 @@ class RevisionCompiler implements CompilerInterface { use HasSources; - const EMPTY_REVISION = 'empty'; + public const EMPTY_REVISION = 'empty'; protected VersionerInterface $versioner; diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index 963c7177d4..3061ff1259 100644 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -36,10 +36,10 @@ class Group extends AbstractModel use ScopeVisibilityTrait; use HasFactory; - const ADMINISTRATOR_ID = 1; - const GUEST_ID = 2; - const MEMBER_ID = 3; - const MODERATOR_ID = 4; + public const ADMINISTRATOR_ID = 1; + public const GUEST_ID = 2; + public const MEMBER_ID = 3; + public const MODERATOR_ID = 4; protected $casts = [ 'id' => 'integer', diff --git a/framework/core/src/Http/Middleware/AuthenticateWithHeader.php b/framework/core/src/Http/Middleware/AuthenticateWithHeader.php index bce59949b6..5ab6313663 100644 --- a/framework/core/src/Http/Middleware/AuthenticateWithHeader.php +++ b/framework/core/src/Http/Middleware/AuthenticateWithHeader.php @@ -21,7 +21,7 @@ class AuthenticateWithHeader implements Middleware { - const TOKEN_PREFIX = 'Token '; + public const TOKEN_PREFIX = 'Token '; public function process(Request $request, Handler $handler): Response { diff --git a/framework/core/src/Http/Rememberer.php b/framework/core/src/Http/Rememberer.php index 434a070780..a8f9a3f30d 100644 --- a/framework/core/src/Http/Rememberer.php +++ b/framework/core/src/Http/Rememberer.php @@ -14,7 +14,7 @@ class Rememberer { - const COOKIE_NAME = 'remember'; + public const COOKIE_NAME = 'remember'; public function __construct( protected CookieFactory $cookie diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index 7e41162bbe..10b1e04f41 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -14,7 +14,7 @@ class Translator extends BaseTranslator implements TranslatorInterface { - const REFERENCE_REGEX = '/^=>\s*([a-z0-9_\-\.]+)$/i'; + public const REFERENCE_REGEX = '/^=>\s*([a-z0-9_\-\.]+)$/i'; public function get($key, array $replace = [], $locale = null): string { diff --git a/framework/core/src/Notification/UnsubscribeToken.php b/framework/core/src/Notification/UnsubscribeToken.php index 035025e10f..01dad8053c 100644 --- a/framework/core/src/Notification/UnsubscribeToken.php +++ b/framework/core/src/Notification/UnsubscribeToken.php @@ -36,7 +36,7 @@ class UnsubscribeToken extends AbstractModel protected $fillable = ['user_id', 'email_type', 'token']; - const TOKEN_LENGTH = 60; + public const TOKEN_LENGTH = 60; public static function generate(int $userId, string $emailType): static { diff --git a/framework/core/src/User/LoginProvider.php b/framework/core/src/User/LoginProvider.php index d463b9de5e..4ee4015a6b 100644 --- a/framework/core/src/User/LoginProvider.php +++ b/framework/core/src/User/LoginProvider.php @@ -30,7 +30,7 @@ class LoginProvider extends AbstractModel public $timestamps = true; - const UPDATED_AT = 'last_login_at'; + public const UPDATED_AT = 'last_login_at'; protected $fillable = ['provider', 'identifier']; From 3e4f6d74c83dafb413ce1101f9437b09251b26c9 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:01:51 +0100 Subject: [PATCH 20/40] refactor: simplify if-else --- framework/core/src/User/Access/Gate.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/framework/core/src/User/Access/Gate.php b/framework/core/src/User/Access/Gate.php index 8d6fa10459..c7743d087c 100644 --- a/framework/core/src/User/Access/Gate.php +++ b/framework/core/src/User/Access/Gate.php @@ -72,11 +72,7 @@ public function allows(User $actor, string $ability, string|AbstractModel|null $ // If no policy covered this permission query, we will only grant // the permission if the actor's groups have it. Otherwise, we will // not allow the user to perform this action. - if ($actor->isAdmin() || $actor->hasPermission($ability)) { - return true; - } - - return false; + return $actor->isAdmin() || $actor->hasPermission($ability); } /** From 9ff2253102315991d7b4c4a51dadc2d05cd09f27 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:03:27 +0100 Subject: [PATCH 21/40] refactor: merge isset calls --- framework/core/src/Forum/Content/Discussion.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Forum/Content/Discussion.php b/framework/core/src/Forum/Content/Discussion.php index 8d5779627d..2122083c93 100644 --- a/framework/core/src/Forum/Content/Discussion.php +++ b/framework/core/src/Forum/Content/Discussion.php @@ -70,7 +70,7 @@ public function __invoke(Document $document, Request $request): Document $posts = []; foreach ($postsApiDocument->data as $resource) { - if ($resource->type === 'posts' && isset($resource->relationships->discussion) && isset($resource->attributes->contentHtml)) { + if ($resource->type === 'posts' && isset($resource->relationships->discussion, $resource->attributes->contentHtml)) { $posts[] = $resource; } } From 8333bf0a4cc4996c6541d5bf487a9fb53cc3f69d Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:07:02 +0100 Subject: [PATCH 22/40] refactor: optimize condition order --- framework/core/src/Api/Endpoint/Create.php | 2 +- framework/core/src/Api/Serializer.php | 4 ++-- framework/core/src/Extension/Bisect.php | 4 ++-- framework/core/src/Foundation/Application.php | 2 +- framework/core/src/Foundation/Site.php | 2 +- .../core/src/Http/Middleware/CheckForMaintenanceMode.php | 2 +- framework/core/src/Http/RouteCollection.php | 2 +- framework/core/src/Install/DatabaseConfig.php | 6 +++--- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/framework/core/src/Api/Endpoint/Create.php b/framework/core/src/Api/Endpoint/Create.php index cdc3061fa4..f9029a90aa 100644 --- a/framework/core/src/Api/Endpoint/Create.php +++ b/framework/core/src/Api/Endpoint/Create.php @@ -89,7 +89,7 @@ public function setUp(): void final protected function fillDefaultValues(Context $context, array &$data): void { foreach ($context->fields($context->resource) as $field) { - if (! has_value($data, $field) && ($default = $field->default)) { + if (($default = $field->default) && ! has_value($data, $field)) { set_value($data, $field, $default($context->withField($field))); } } diff --git a/framework/core/src/Api/Serializer.php b/framework/core/src/Api/Serializer.php index 15678c0a96..cd0352df98 100644 --- a/framework/core/src/Api/Serializer.php +++ b/framework/core/src/Api/Serializer.php @@ -93,8 +93,8 @@ private function addToMap(Resource $resource, mixed $model, array $include): arr $this->whenResolved($value, function (mixed $value) use ($key, $field, $context) { if ( - ($value = $field->serializeValue($value, $context)) || - ! $field instanceof Relationship + ! $field instanceof Relationship || + ($value = $field->serializeValue($value, $context)) ) { set_value($this->map[$key], $field, $value); } diff --git a/framework/core/src/Extension/Bisect.php b/framework/core/src/Extension/Bisect.php index 77b8ce1c92..215f238aa3 100644 --- a/framework/core/src/Extension/Bisect.php +++ b/framework/core/src/Extension/Bisect.php @@ -107,11 +107,11 @@ protected function bisect(BisectState $state): ?array return $current; } - if (count($relevantEnabled) === 1 && $issue) { + if ($issue && count($relevantEnabled) === 1) { return $this->foundIssue($relevantEnabled[0]); } - if (count($relevantDisabled) === 1 && ! $issue) { + if (! $issue && count($relevantDisabled) === 1) { return $this->foundIssue($relevantDisabled[0]); } diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index fccc664148..11522d58b4 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -93,7 +93,7 @@ protected function registerBaseServiceProviders(): void public function register($provider, $force = false): ServiceProvider { - if (($registered = $this->getProvider($provider)) && ! $force) { + if (! $force && ($registered = $this->getProvider($provider))) { return $registered; } diff --git a/framework/core/src/Foundation/Site.php b/framework/core/src/Foundation/Site.php index 0cc0043b05..36b31f5a0d 100644 --- a/framework/core/src/Foundation/Site.php +++ b/framework/core/src/Foundation/Site.php @@ -35,7 +35,7 @@ public static function fromPaths(array $paths): SiteInterface ini_set('display_errors', 0); - if (! $config->inDebugMode() && function_exists('error_reporting')) { + if (function_exists('error_reporting') && ! $config->inDebugMode()) { error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); } diff --git a/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php b/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php index 9941b67ce5..29157b5834 100644 --- a/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php +++ b/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php @@ -30,7 +30,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $actor = RequestUtil::getActor($request); $isRouteExcluded = in_array($request->getAttribute('routeName'), $this->exemptRoutes, true); - if ($this->maintenance->inMaintenanceMode() && ! $actor->isAdmin() && ! $isRouteExcluded) { + if (! $isRouteExcluded && $this->maintenance->inMaintenanceMode() && ! $actor->isAdmin()) { throw new MaintenanceModeException('The forum is currently in maintenance mode.'); } diff --git a/framework/core/src/Http/RouteCollection.php b/framework/core/src/Http/RouteCollection.php index 9d20e22e05..27a760267f 100644 --- a/framework/core/src/Http/RouteCollection.php +++ b/framework/core/src/Http/RouteCollection.php @@ -131,7 +131,7 @@ public function getPath(string $name, array $parameters = []): string // and the second element is a regex into which the parameter value is inserted, if the parameter matches. foreach ($this->reverse[$name] as $parts) { foreach ($parts as $i => $part) { - if (is_array($part) && Arr::exists($parameters, $part[0]) && $i > $maxMatches) { + if ($i > $maxMatches && is_array($part) && Arr::exists($parameters, $part[0])) { $maxMatches = $i; $matchingParts = $parts; } diff --git a/framework/core/src/Install/DatabaseConfig.php b/framework/core/src/Install/DatabaseConfig.php index 003bbcbc8d..5d1b8ea3ff 100644 --- a/framework/core/src/Install/DatabaseConfig.php +++ b/framework/core/src/Install/DatabaseConfig.php @@ -46,11 +46,11 @@ private function validate(): void throw new ValidationFailed('Currently, only MySQL, MariaDB, SQLite and PostgreSQL are supported.'); } - if (in_array($this->driver, ['mysql', 'mariadb', 'pgsql']) && empty($this->host)) { + if (empty($this->host) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) { throw new ValidationFailed('Please specify the hostname of your database server.'); } - if (in_array($this->driver, ['mysql', 'mariadb', 'pgsql']) && ($this->port < 1 || $this->port > 65535)) { + if (($this->port < 1 || $this->port > 65535) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) { throw new ValidationFailed('Please provide a valid port number between 1 and 65535.'); } @@ -58,7 +58,7 @@ private function validate(): void throw new ValidationFailed('Please specify the database name.'); } - if (in_array($this->driver, ['mysql', 'mariadb', 'pgsql']) && empty($this->username)) { + if (empty($this->username) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) { throw new ValidationFailed('Please specify the username for accessing the database.'); } From 25865eabedca1813d4af84224ae83c60b0852aa7 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:10:54 +0100 Subject: [PATCH 23/40] refactor: cleanup if-else branches --- framework/core/src/Api/Middleware/ThrottleApi.php | 4 +++- .../src/Api/Resource/AbstractDatabaseResource.php | 4 ++-- framework/core/src/Extension/Bisect.php | 4 ++-- .../src/Extension/Console/ToggleExtensionCommand.php | 12 ++++++------ .../src/Foundation/ErrorHandling/ViewFormatter.php | 4 ++-- framework/core/src/Foundation/InstalledApp.php | 4 +++- framework/core/src/Frontend/Document.php | 4 ++-- framework/core/src/Http/AccessToken.php | 5 ++--- framework/core/src/Http/Server.php | 4 +++- .../src/Settings/MemoryCacheSettingsRepository.php | 4 +++- framework/core/src/User/Access/AbstractPolicy.php | 4 +++- framework/core/src/User/User.php | 4 +++- 12 files changed, 34 insertions(+), 23 deletions(-) diff --git a/framework/core/src/Api/Middleware/ThrottleApi.php b/framework/core/src/Api/Middleware/ThrottleApi.php index 317695678b..fb68cd8ab0 100644 --- a/framework/core/src/Api/Middleware/ThrottleApi.php +++ b/framework/core/src/Api/Middleware/ThrottleApi.php @@ -42,7 +42,9 @@ public function throttle(Request $request): bool // Anything else is ignored. if ($result === false) { return false; - } elseif ($result === true) { + } + + if ($result === true) { $throttle = true; } } diff --git a/framework/core/src/Api/Resource/AbstractDatabaseResource.php b/framework/core/src/Api/Resource/AbstractDatabaseResource.php index b7a7a0bb54..cc953871b1 100644 --- a/framework/core/src/Api/Resource/AbstractDatabaseResource.php +++ b/framework/core/src/Api/Resource/AbstractDatabaseResource.php @@ -74,9 +74,9 @@ public function getValue(object $model, Field $field, Context $context): mixed { if ($field instanceof Relationship) { return $this->getRelationshipValue($model, $field, $context); - } else { - return $this->getAttributeValue($model, $field, $context); } + + return $this->getAttributeValue($model, $field, $context); } /** diff --git a/framework/core/src/Extension/Bisect.php b/framework/core/src/Extension/Bisect.php index 215f238aa3..bbf8246e15 100644 --- a/framework/core/src/Extension/Bisect.php +++ b/framework/core/src/Extension/Bisect.php @@ -117,9 +117,9 @@ protected function bisect(BisectState $state): ?array if ($issue) { return $this->bisect($this->state->advance($low, $mid)); - } else { - return $this->bisect($this->state->advance($mid + 1, $high)); } + + return $this->bisect($this->state->advance($mid + 1, $high)); } protected function foundIssue(string $id): array diff --git a/framework/core/src/Extension/Console/ToggleExtensionCommand.php b/framework/core/src/Extension/Console/ToggleExtensionCommand.php index e64c7e37dc..1e722c934c 100644 --- a/framework/core/src/Extension/Console/ToggleExtensionCommand.php +++ b/framework/core/src/Extension/Console/ToggleExtensionCommand.php @@ -46,19 +46,19 @@ protected function fire(): int $this->info("The '$name' extension is already enabled."); return Command::FAILURE; - } else { - $this->info("Enabling '$name' extension..."); - $this->extensionManager->enable($name); } + + $this->info("Enabling '$name' extension..."); + $this->extensionManager->enable($name); } else { if (! $this->extensionManager->isEnabled($name)) { $this->info("The '$name' extension is already disabled."); return Command::FAILURE; - } else { - $this->info("Disabling '$name' extension..."); - $this->extensionManager->disable($name); } + + $this->info("Disabling '$name' extension..."); + $this->extensionManager->disable($name); } return Command::SUCCESS; diff --git a/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php b/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php index 5b496e1ea7..512ffd3533 100644 --- a/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php +++ b/framework/core/src/Foundation/ErrorHandling/ViewFormatter.php @@ -54,9 +54,9 @@ private function determineView(HandledError $error): string if (in_array($type, self::ERRORS_WITH_VIEWS)) { return "flarum.forum::error.$type"; - } else { - return 'flarum.forum::error.default'; } + + return 'flarum.forum::error.default'; } private function getMessage(HandledError $error): string diff --git a/framework/core/src/Foundation/InstalledApp.php b/framework/core/src/Foundation/InstalledApp.php index 94561a2f59..44e8a5d309 100644 --- a/framework/core/src/Foundation/InstalledApp.php +++ b/framework/core/src/Foundation/InstalledApp.php @@ -37,7 +37,9 @@ public function getRequestHandler(): RequestHandlerInterface { if ($this->config->inHighMaintenanceMode()) { return $this->container->make('flarum.maintenance.handler'); - } elseif ($this->needsUpdate()) { + } + + if ($this->needsUpdate()) { return $this->getUpdaterHandler(); } diff --git a/framework/core/src/Frontend/Document.php b/framework/core/src/Frontend/Document.php index ed242495af..eebdec5f49 100644 --- a/framework/core/src/Frontend/Document.php +++ b/framework/core/src/Frontend/Document.php @@ -347,8 +347,8 @@ protected static function setQueryParam(string $url, string $key, ?string $value } return $newUrl; - } else { - return $url; } + + return $url; } } diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php index cc42186c62..864e19b5ea 100644 --- a/framework/core/src/Http/AccessToken.php +++ b/framework/core/src/Http/AccessToken.php @@ -90,11 +90,10 @@ public static function make(int $userId): static { if (static::class === self::class) { throw new \Exception('Use of AccessToken::generate() is not allowed: use the `generate` method on one of the subclasses.'); - } else { - $token = new static; - $token->type = static::$type; } + $token = new static; + $token->type = static::$type; $token->token = Str::random(40); $token->user_id = $userId; $token->created_at = Carbon::now(); diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index 5616dc9e65..dd297c839f 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -98,7 +98,9 @@ private function cleanBootExceptionLog(Throwable $error): void
$error
ERROR; exit(1); - } elseif ($container->has(LoggerInterface::class)) { + } + + if ($container->has(LoggerInterface::class)) { // If the application booted far enough for the logger to be available, we will log the error there // Considering most boot errors are related to database or extensions, the logger should already be loaded // We check for LoggerInterface binding because it's a constructor dependency of LogReporter, diff --git a/framework/core/src/Settings/MemoryCacheSettingsRepository.php b/framework/core/src/Settings/MemoryCacheSettingsRepository.php index 5f75849f36..7642c01c8a 100644 --- a/framework/core/src/Settings/MemoryCacheSettingsRepository.php +++ b/framework/core/src/Settings/MemoryCacheSettingsRepository.php @@ -35,7 +35,9 @@ public function get(string $key, mixed $default = null): mixed { if (array_key_exists($key, $this->cache)) { return $this->cache[$key]; - } elseif (! $this->isCached) { + } + + if (! $this->isCached) { return Arr::get($this->all(), $key, $default); } diff --git a/framework/core/src/User/Access/AbstractPolicy.php b/framework/core/src/User/Access/AbstractPolicy.php index 16bd326cb7..1fc7f96e47 100644 --- a/framework/core/src/User/Access/AbstractPolicy.php +++ b/framework/core/src/User/Access/AbstractPolicy.php @@ -74,7 +74,9 @@ public function sanitizeResult(string|bool|null $result): ?string { if ($result === true) { return $this->allow(); - } elseif ($result === false) { + } + + if ($result === false) { return $this->deny(); } diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 87a4ca3fff..711a67698b 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -276,7 +276,9 @@ public function checkPassword(#[\SensitiveParameter] string $password): bool if ($result === false) { return false; - } elseif ($result === true) { + } + + if ($result === true) { $valid = true; } } From 0e0091433894954bbdcbcdce222803a180b5f3f6 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:11:42 +0100 Subject: [PATCH 24/40] refactor: trim first, then convert to lowercase --- framework/core/src/User/AvatarValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/User/AvatarValidator.php b/framework/core/src/User/AvatarValidator.php index ade155ba20..1c4dff7782 100644 --- a/framework/core/src/User/AvatarValidator.php +++ b/framework/core/src/User/AvatarValidator.php @@ -64,7 +64,7 @@ protected function assertFileMimes(UploadedFileInterface $file): void $phpExtensions = ['php', 'php3', 'php4', 'php5', 'phtml']; $fileExtension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION); - if (in_array(trim(strtolower($fileExtension)), $phpExtensions)) { + if (in_array(strtolower(trim($fileExtension)), $phpExtensions)) { $this->raise('mimes', [':values' => implode(', ', $allowedTypes)]); } From d6744c907589c0f333b58ca27d816ffec6e47b03 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:15:44 +0100 Subject: [PATCH 25/40] refactor: use null coalescing operator --- framework/core/src/Forum/ForumServiceProvider.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index e8c05217a6..963b28012e 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -230,11 +230,7 @@ protected function setDefaultRoute(RouteCollection $routes, Container $container $factory = $container->make(RouteHandlerFactory::class); $defaultRoute = $container->make('flarum.settings')->get('default_route'); - if (isset($routes->getRouteData()[0]['GET'][$defaultRoute]['handler'])) { - $toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]['handler']; - } else { - $toDefaultController = $factory->toForum(Content\Index::class); - } + $toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]['handler'] ?? $factory->toForum(Content\Index::class); $routes->get( '/', From ed8cf27156e98822f6decd6c93b37a89797271c4 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:16:04 +0100 Subject: [PATCH 26/40] refactor: use short list syntax --- framework/core/src/Install/Console/UserDataProvider.php | 2 +- framework/core/src/Install/Controller/InstallController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Install/Console/UserDataProvider.php b/framework/core/src/Install/Console/UserDataProvider.php index 60a71947a0..d546d9d9a7 100644 --- a/framework/core/src/Install/Console/UserDataProvider.php +++ b/framework/core/src/Install/Console/UserDataProvider.php @@ -54,7 +54,7 @@ private function getDatabaseConfiguration(): DatabaseConfig $host = $this->ask('Database host (required):', required: true); if (Str::contains($host, ':')) { - list($host, $port) = explode(':', $host, 2); + [$host, $port] = explode(':', $host, 2); } $user = $this->ask('Database user (required):', required: true); diff --git a/framework/core/src/Install/Controller/InstallController.php b/framework/core/src/Install/Controller/InstallController.php index 484c9e3d36..f3297d19f7 100644 --- a/framework/core/src/Install/Controller/InstallController.php +++ b/framework/core/src/Install/Controller/InstallController.php @@ -85,7 +85,7 @@ private function makeDatabaseConfig(array $input): DatabaseConfig }; if (Str::contains($host, ':')) { - list($host, $port) = explode(':', $host, 2); + [$host, $port] = explode(':', $host, 2); } return new DatabaseConfig( From 85bfc72fabb66bf5901cdab7e1cec8ce9376e182 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:16:48 +0100 Subject: [PATCH 27/40] refactor: replace in_array() with array_key_exists --- framework/core/src/Search/SearchCriteria.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Search/SearchCriteria.php b/framework/core/src/Search/SearchCriteria.php index c13f408d1c..dc9ed44335 100644 --- a/framework/core/src/Search/SearchCriteria.php +++ b/framework/core/src/Search/SearchCriteria.php @@ -41,6 +41,6 @@ public function __construct( public function isFulltext(): bool { - return in_array('q', array_keys($this->filters), true); + return array_key_exists('q', $this->filters); } } From 984c9ba79d357a9e1322cac1f4353138d156968e Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:21:23 +0100 Subject: [PATCH 28/40] refactor: use proper callbacks istead of relying on call_user_func* --- framework/core/src/Foundation/Application.php | 2 +- framework/core/src/User/Access/AbstractPolicy.php | 4 ++-- framework/core/src/User/User.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index 11522d58b4..c82a62118d 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -197,7 +197,7 @@ public function booted(mixed $callback): void protected function fireAppCallbacks(array $callbacks): void { foreach ($callbacks as $callback) { - call_user_func($callback, $this); + $callback($this); } } diff --git a/framework/core/src/User/Access/AbstractPolicy.php b/framework/core/src/User/Access/AbstractPolicy.php index 1fc7f96e47..4e02ed19e1 100644 --- a/framework/core/src/User/Access/AbstractPolicy.php +++ b/framework/core/src/User/Access/AbstractPolicy.php @@ -45,7 +45,7 @@ public function checkAbility(User $actor, string $ability, string|AbstractModel| // If a specific method for this ability is defined, // call that and return any non-null results if (method_exists($this, $ability)) { - $result = $this->sanitizeResult(call_user_func_array([$this, $ability], [$actor, $instance])); + $result = $this->sanitizeResult($this->{$ability}($actor, $instance)); if (! is_null($result)) { return $result; @@ -54,7 +54,7 @@ public function checkAbility(User $actor, string $ability, string|AbstractModel| // If a "total access" method is defined, try that. if (method_exists($this, 'can')) { - return $this->sanitizeResult(call_user_func_array([$this, 'can'], [$actor, $ability, $instance])); + return $this->sanitizeResult($this->can($actor, $ability, $instance)); } return null; diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 711a67698b..e372bd7b5f 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -422,7 +422,7 @@ public function setPreference(string $key, mixed $value): static $preferences = $this->preferences; if (! is_null($transformer = static::$preferences[$key]['transformer'])) { - $preferences[$key] = call_user_func($transformer, $value); + $preferences[$key] = $transformer($value); } else { $preferences[$key] = $value; } From 99b1b7c37b3c35d687936396f16b957b0c897b31 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:24:34 +0100 Subject: [PATCH 29/40] refactor: wrap condition with parentheses to clarify operation order --- framework/core/src/Search/Database/AbstractSearcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Search/Database/AbstractSearcher.php b/framework/core/src/Search/Database/AbstractSearcher.php index dec58b3b6a..2ac2bfae39 100644 --- a/framework/core/src/Search/Database/AbstractSearcher.php +++ b/framework/core/src/Search/Database/AbstractSearcher.php @@ -52,7 +52,7 @@ public function search(SearchCriteria $criteria): SearchResults // results. If there are, we will get rid of that extra result. $results = $query->get(); - if ($areMoreResults = $criteria->limit > 0 && $results->count() > $criteria->limit) { + if ($areMoreResults = ($criteria->limit > 0 && $results->count() > $criteria->limit)) { $results->pop(); } From 8b65f1df192d5977ff01cde0dad957666b3ef476 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:25:30 +0100 Subject: [PATCH 30/40] refactor: drop property, ExtractsListingParams trait already defines it --- framework/core/src/Api/Endpoint/Index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/core/src/Api/Endpoint/Index.php b/framework/core/src/Api/Endpoint/Index.php index c6f815f7c1..e023bc1139 100644 --- a/framework/core/src/Api/Endpoint/Index.php +++ b/framework/core/src/Api/Endpoint/Index.php @@ -44,7 +44,6 @@ class Index extends Endpoint use HasCustomHooks; public Closure $paginationResolver; - public ?string $defaultSort = null; protected ?Closure $query = null; public function __construct(string $name) From ed8d7e4e78d1e2b7ff8fb74f79c43e7218ab479d Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:28:17 +0100 Subject: [PATCH 31/40] refactor: remove unused imports --- framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php | 1 - framework/core/src/Extend/Model.php | 1 - framework/core/src/User/AvatarValidator.php | 1 - 3 files changed, 3 deletions(-) diff --git a/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php b/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php index 0c319c600f..2890d6e6b5 100644 --- a/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php +++ b/framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php @@ -13,7 +13,6 @@ use Flarum\Api\Resource\AbstractDatabaseResource; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Str; use Tobyz\JsonApiServer\Context; diff --git a/framework/core/src/Extend/Model.php b/framework/core/src/Extend/Model.php index b35dba5d70..8c5db1f5c1 100644 --- a/framework/core/src/Extend/Model.php +++ b/framework/core/src/Extend/Model.php @@ -13,7 +13,6 @@ use Flarum\Extension\Extension; use Flarum\Foundation\ContainerUtil; use Illuminate\Contracts\Container\Container; -use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Arr; /** diff --git a/framework/core/src/User/AvatarValidator.php b/framework/core/src/User/AvatarValidator.php index 1c4dff7782..91198afcab 100644 --- a/framework/core/src/User/AvatarValidator.php +++ b/framework/core/src/User/AvatarValidator.php @@ -13,7 +13,6 @@ use Flarum\Foundation\ValidationException; use Flarum\Locale\TranslatorInterface; use Illuminate\Validation\Factory; -use Illuminate\Validation\Validator; use Intervention\Gif\Exceptions\DecoderException as GifDecoderException; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\ImageManager; From b91eb45d9f7cab5e9a46ca3db9fb4e0834743f6f Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:29:48 +0100 Subject: [PATCH 32/40] refactor: remove unused variables --- framework/core/src/Api/Resource/UserResource.php | 2 +- framework/core/src/Forum/Controller/LogInController.php | 2 -- framework/core/src/Forum/Controller/LogOutController.php | 2 +- framework/core/src/Foundation/UninstalledSite.php | 2 +- framework/core/src/Locale/Translator.php | 2 +- framework/core/src/Notification/NotificationServiceProvider.php | 2 +- framework/core/src/Notification/NotificationSyncer.php | 2 +- 7 files changed, 6 insertions(+), 8 deletions(-) diff --git a/framework/core/src/Api/Resource/UserResource.php b/framework/core/src/Api/Resource/UserResource.php index 1b98a639b5..11e8d10cc1 100644 --- a/framework/core/src/Api/Resource/UserResource.php +++ b/framework/core/src/Api/Resource/UserResource.php @@ -434,7 +434,7 @@ private function retrieveAvatarFromUrl(string $url): ?string try { $response = $client->get($url); - } catch (\Exception $e) { + } catch (\Exception) { return null; } diff --git a/framework/core/src/Forum/Controller/LogInController.php b/framework/core/src/Forum/Controller/LogInController.php index a213cbdb89..5da00a09d8 100644 --- a/framework/core/src/Forum/Controller/LogInController.php +++ b/framework/core/src/Forum/Controller/LogInController.php @@ -48,8 +48,6 @@ public function handle(Request $request): ResponseInterface $params = Arr::only($body, ['identification', 'password', 'remember']); $isHtmlRequest = RequestUtil::isHtmlRequest($request); - $errors = null; - if ($isHtmlRequest) { $validator = $this->validator->basic()->prepare($body)->validator(); diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index 43002eafeb..596ff8f54f 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -82,7 +82,7 @@ protected function sanitizeReturnUrl(string $url, string $base): Uri try { $parsedUrl = new Uri($url); - } catch (\InvalidArgumentException $e) { + } catch (\InvalidArgumentException) { return new Uri($base); } diff --git a/framework/core/src/Foundation/UninstalledSite.php b/framework/core/src/Foundation/UninstalledSite.php index 21994004b7..1ecb43daf1 100644 --- a/framework/core/src/Foundation/UninstalledSite.php +++ b/framework/core/src/Foundation/UninstalledSite.php @@ -55,7 +55,7 @@ protected function bootLaravel(): Container $app->instance('flarum.config', new Config(['url' => $this->baseUrl])); $app->alias('flarum.config', Config::class); $app->instance('flarum.debug', true); - $app->instance('config', $config = $this->getIlluminateConfig()); + $app->instance('config', $this->getIlluminateConfig()); $this->registerLogger($app); diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index 10b1e04f41..dba663484c 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -55,7 +55,7 @@ private function parseCatalogue(MessageCatalogueInterface $catalogue): void { foreach ($catalogue->all() as $domain => $messages) { foreach ($messages as $id => $translation) { - if (! empty($translation) && preg_match(self::REFERENCE_REGEX, $translation, $matches)) { + if (! empty($translation) && preg_match(self::REFERENCE_REGEX, $translation)) { $catalogue->set($id, $this->getTranslation($catalogue, $id, $domain), $domain); } } diff --git a/framework/core/src/Notification/NotificationServiceProvider.php b/framework/core/src/Notification/NotificationServiceProvider.php index 98c4d1d570..c409604e61 100644 --- a/framework/core/src/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Notification/NotificationServiceProvider.php @@ -64,7 +64,7 @@ protected function addType(string $blueprintClass, array $driversEnabledByDefaul $blueprintClass::getSubjectModel() ); - foreach (NotificationSyncer::getNotificationDrivers() as $driverName => $driver) { + foreach (NotificationSyncer::getNotificationDrivers() as $driver) { $driver->registerType( $blueprintClass, $driversEnabledByDefault diff --git a/framework/core/src/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php index c1d56ef0e1..37d6793128 100644 --- a/framework/core/src/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -103,7 +103,7 @@ public function sync(BlueprintInterface $blueprint, array $users): void // receiving this notification for the first time (we know because they // didn't have a record in the database). As both operations can be // intensive on resources (database and mail server), we queue them. - foreach (static::getNotificationDrivers() as $driverName => $driver) { + foreach (static::getNotificationDrivers() as $driver) { $driver->send($blueprint, $newRecipients); } } From efced7b663261aacbc7f72f7f62c7fa727823e60 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:33:20 +0100 Subject: [PATCH 33/40] refactor: remove unused parameters --- framework/core/src/Extension/ExtensionManager.php | 2 +- framework/core/src/Forum/Content/Posts.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index fb39bee581..37fd51c517 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -106,7 +106,7 @@ public function getExtensions(): Collection $this->setEnabledExtensions($enabledExtensions); } - $this->extensions = $extensions->sortBy(function ($extension, $name) { + $this->extensions = $extensions->sortBy(function ($extension) { return $extension->getTitle(); }); } diff --git a/framework/core/src/Forum/Content/Posts.php b/framework/core/src/Forum/Content/Posts.php index a7ea5eaa10..48879e7c1c 100644 --- a/framework/core/src/Forum/Content/Posts.php +++ b/framework/core/src/Forum/Content/Posts.php @@ -69,7 +69,7 @@ public function __invoke(Document $document, Request $request): Document return $document; } - protected function getApiDocument(Request $request, array $params, ?string $q): ?object + protected function getApiDocument(Request $request, array $params): ?object { return json_decode( $this->api From d37c1f259a0e0323879236113e92c1b2bc474e6e Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:41:28 +0100 Subject: [PATCH 34/40] refactor: change method call as signature has changed --- framework/core/src/Forum/Content/Posts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Forum/Content/Posts.php b/framework/core/src/Forum/Content/Posts.php index 48879e7c1c..d83c8cd01d 100644 --- a/framework/core/src/Forum/Content/Posts.php +++ b/framework/core/src/Forum/Content/Posts.php @@ -56,7 +56,7 @@ public function __invoke(Document $document, Request $request): Document $params['filter']['q'] = $q; } - $apiDocument = $this->getApiDocument($request, $params, $q); + $apiDocument = $this->getApiDocument($request, $params); $document->title = $this->translator->trans('core.forum.index.meta_title_text'); // $document->content = $this->view->make('flarum.forum::frontend.content.index', compact('apiDocument', 'page')); From 1331d396a93b6a0b3f846fa79ad6e64d092d29cb Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:57:52 +0100 Subject: [PATCH 35/40] refactor: re-add PHPDoc for phpstan Apparently PHPStan can't tell that the scope returns a model instance. --- framework/core/src/Api/Resource/UserResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/src/Api/Resource/UserResource.php b/framework/core/src/Api/Resource/UserResource.php index 11e8d10cc1..3d5f88d373 100644 --- a/framework/core/src/Api/Resource/UserResource.php +++ b/framework/core/src/Api/Resource/UserResource.php @@ -231,6 +231,7 @@ public function fields(): array }) ->set(function (User $user, ?string $value, Context $context) { if ($value) { + /** @var RegistrationToken $token */ $token = RegistrationToken::validOrFail($value); $context->setParam('token', $token); From 5319d666852b82eb71de8f5cf0af2bde70aea9f0 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:58:36 +0100 Subject: [PATCH 36/40] refactor: remove nullable type This method can't return `null` - we are throwing an exception if that's the case. --- framework/core/src/User/RegistrationToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/User/RegistrationToken.php b/framework/core/src/User/RegistrationToken.php index c4bf3dd114..db774f8be7 100644 --- a/framework/core/src/User/RegistrationToken.php +++ b/framework/core/src/User/RegistrationToken.php @@ -64,7 +64,7 @@ public static function generate(string $provider, string $identifier, array $att * * @throws InvalidConfirmationTokenException */ - public function scopeValidOrFail(Builder $query, #[\SensitiveParameter] string $token): ?RegistrationToken + public function scopeValidOrFail(Builder $query, #[\SensitiveParameter] string $token): RegistrationToken { /** @var RegistrationToken|null $token */ $token = $query->find($token); From 7065e502c12fe96941a9ffd00fa6ab0b75f50d16 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:19:55 +0100 Subject: [PATCH 37/40] refactor: add second parameter to json_decode() calls --- framework/core/src/Database/Migrator.php | 5 +---- framework/core/src/Forum/Content/Discussion.php | 10 ++++++---- framework/core/src/Forum/Content/Index.php | 5 +++-- framework/core/src/Forum/Content/Posts.php | 5 +++-- framework/core/src/Forum/Content/User.php | 5 +++-- .../core/src/Forum/Controller/LogInController.php | 2 +- .../core/src/Forum/Controller/RegisterController.php | 2 +- .../core/src/Frontend/FrontendServiceProvider.php | 2 +- framework/core/src/Group/GroupRepository.php | 2 +- 9 files changed, 20 insertions(+), 18 deletions(-) diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index a25362d121..d7071c7367 100644 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -176,11 +176,8 @@ protected function resolveAndRunClosureMigration(string $path, string $file, str /** * Get all of the migration files in a given path. - * - * @param string $path - * @return array */ - public function getMigrationFiles($path) + public function getMigrationFiles(string $path): array { $files = $this->files->glob($path.'/*_*.php'); diff --git a/framework/core/src/Forum/Content/Discussion.php b/framework/core/src/Forum/Content/Discussion.php index 2122083c93..5ca0fc6352 100644 --- a/framework/core/src/Forum/Content/Discussion.php +++ b/framework/core/src/Forum/Content/Discussion.php @@ -108,12 +108,13 @@ protected function getApiDocument(Request $request, string $id, array $params = $params['bySlug'] = true; return json_decode( - $this->api + json: $this->api ->withoutErrorHandling() ->withParentRequest($request) ->withQueryParams($params) ->get("/discussions/$id") - ->getBody() + ->getBody(), + associative: false ); } @@ -125,12 +126,13 @@ protected function getApiDocument(Request $request, string $id, array $params = protected function getPostsApiDocument(Request $request, array $params): object { return json_decode( - $this->api + json: $this->api ->withoutErrorHandling() ->withParentRequest($request) ->withQueryParams($params) ->get('/posts') - ->getBody() + ->getBody(), + associative: false ); } } diff --git a/framework/core/src/Forum/Content/Index.php b/framework/core/src/Forum/Content/Index.php index 6120494efe..eb3c2b5ab6 100644 --- a/framework/core/src/Forum/Content/Index.php +++ b/framework/core/src/Forum/Content/Index.php @@ -73,12 +73,13 @@ public function __invoke(Document $document, Request $request): Document protected function getApiDocument(Request $request, array $params): object { return json_decode( - $this->api + json: $this->api ->withoutErrorHandling() ->withParentRequest($request) ->withQueryParams($params) ->get('/discussions') - ->getBody() + ->getBody(), + associative: false ); } } diff --git a/framework/core/src/Forum/Content/Posts.php b/framework/core/src/Forum/Content/Posts.php index d83c8cd01d..3b5f9701df 100644 --- a/framework/core/src/Forum/Content/Posts.php +++ b/framework/core/src/Forum/Content/Posts.php @@ -72,12 +72,13 @@ public function __invoke(Document $document, Request $request): Document protected function getApiDocument(Request $request, array $params): ?object { return json_decode( - $this->api + json: $this->api ->withoutErrorHandling() ->withParentRequest($request) ->withQueryParams($params) ->get('/posts') - ->getBody() + ->getBody(), + associative: false ); } } diff --git a/framework/core/src/Forum/Content/User.php b/framework/core/src/Forum/Content/User.php index 8ecee2b0c1..490fdc93e8 100644 --- a/framework/core/src/Forum/Content/User.php +++ b/framework/core/src/Forum/Content/User.php @@ -47,11 +47,12 @@ public function __invoke(Document $document, Request $request): Document protected function getApiDocument(Request $request, string $username): object { return json_decode( - $this->api + json: $this->api ->withoutErrorHandling() ->withParentRequest($request) ->withQueryParams(['bySlug' => true]) - ->get("/users/$username")->getBody() + ->get("/users/$username")->getBody(), + associative: false ); } } diff --git a/framework/core/src/Forum/Controller/LogInController.php b/framework/core/src/Forum/Controller/LogInController.php index 5da00a09d8..b5b1f9fefa 100644 --- a/framework/core/src/Forum/Controller/LogInController.php +++ b/framework/core/src/Forum/Controller/LogInController.php @@ -64,7 +64,7 @@ public function handle(Request $request): ResponseInterface $response = $this->apiClient->withParentRequest($request)->withBody($params)->post('/token'); if ($response->getStatusCode() === 200) { - $data = json_decode($response->getBody()); + $data = json_decode($response->getBody(), false); $token = AccessToken::findValid($data->token); diff --git a/framework/core/src/Forum/Controller/RegisterController.php b/framework/core/src/Forum/Controller/RegisterController.php index a261b33413..aee7c8a9e8 100644 --- a/framework/core/src/Forum/Controller/RegisterController.php +++ b/framework/core/src/Forum/Controller/RegisterController.php @@ -32,7 +32,7 @@ public function handle(Request $request): ResponseInterface $response = $this->api->withParentRequest($request)->withBody($params)->post('/users'); - $body = json_decode($response->getBody()); + $body = json_decode($response->getBody(), false); if (isset($body->data)) { $userId = $body->data->id; diff --git a/framework/core/src/Frontend/FrontendServiceProvider.php b/framework/core/src/Frontend/FrontendServiceProvider.php index 8a447363be..d598417baf 100644 --- a/framework/core/src/Frontend/FrontendServiceProvider.php +++ b/framework/core/src/Frontend/FrontendServiceProvider.php @@ -141,7 +141,7 @@ function (Container $container) { $this->container->singleton( 'flarum.frontend.custom_less_functions', function (Container $container) { - $extensionsEnabled = json_decode($container->make(SettingsRepositoryInterface::class)->get('extensions_enabled')); + $extensionsEnabled = json_decode($container->make(SettingsRepositoryInterface::class)->get('extensions_enabled'), true); // Please note that these functions do not go through the same transformation which the Theme extender's // `addCustomLessFunction` method does. You'll need to use the correct Less tree return type, and get diff --git a/framework/core/src/Group/GroupRepository.php b/framework/core/src/Group/GroupRepository.php index 79fd4e3eee..bdc12a64ed 100644 --- a/framework/core/src/Group/GroupRepository.php +++ b/framework/core/src/Group/GroupRepository.php @@ -17,7 +17,7 @@ class GroupRepository /** * @return Builder */ - public function query() + public function query(): Builder { return Group::query(); } From 5600e50d537cc56fd027cd947aad2b7eda62741f Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:24:19 +0100 Subject: [PATCH 38/40] refactor: use strict comparison where possible --- .../core/src/Api/Controller/UninstallExtensionController.php | 2 +- framework/core/src/Database/Migrator.php | 2 +- framework/core/src/Extension/ExtensionManager.php | 2 +- framework/core/src/Foundation/Console/InfoCommand.php | 2 +- framework/core/src/Http/CookieFactory.php | 4 +--- framework/core/src/Install/Prerequisite/WritablePaths.php | 4 ++-- framework/core/src/Install/Steps/EnableBundledExtensions.php | 2 +- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/framework/core/src/Api/Controller/UninstallExtensionController.php b/framework/core/src/Api/Controller/UninstallExtensionController.php index 8f0cfb01ef..2d567dc4ce 100644 --- a/framework/core/src/Api/Controller/UninstallExtensionController.php +++ b/framework/core/src/Api/Controller/UninstallExtensionController.php @@ -27,7 +27,7 @@ protected function delete(ServerRequestInterface $request): void $name = Arr::get($request->getQueryParams(), 'name'); - if ($this->extensions->getExtension($name) == null) { + if ($this->extensions->getExtension($name) === null) { return; } diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index d7071c7367..8dccce81c4 100644 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -50,7 +50,7 @@ public function runMigrationList(string $path, array $migrations, ?Extension $ex // First we will just make sure that there are any migrations to run. If there // aren't, we will just make a note of it to the developer so they're aware // that all the migrations have been run against this database system. - if (count($migrations) == 0) { + if (count($migrations) === 0) { $this->note('Nothing to migrate.'); return; diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 37fd51c517..f0701a9493 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -470,7 +470,7 @@ public static function resolveExtensionOrder(array $extensionList): array }, $validOutput)); // Reversed as required by Kahn's algorithm. foreach ($inDegreeCount as $id => $count) { - if ($count != 0) { + if ($count !== 0) { $circularDependencies[] = $id; } } diff --git a/framework/core/src/Foundation/Console/InfoCommand.php b/framework/core/src/Foundation/Console/InfoCommand.php index 06b9c6e791..b2aa4beabf 100644 --- a/framework/core/src/Foundation/Console/InfoCommand.php +++ b/framework/core/src/Foundation/Console/InfoCommand.php @@ -113,7 +113,7 @@ private function findPackageVersion(string $path, ?string $fallback = null): ?st chdir($cwd); - if ($status == 0) { + if ($status === 0) { return isset($fallback) ? "$fallback ($output[0])" : $output[0]; } } diff --git a/framework/core/src/Http/CookieFactory.php b/framework/core/src/Http/CookieFactory.php index bf955ccb0a..a9e518c062 100644 --- a/framework/core/src/Http/CookieFactory.php +++ b/framework/core/src/Http/CookieFactory.php @@ -52,9 +52,7 @@ public function make(string $name, ?string $value = null, ?int $maxAge = null): ->withExpires(time() + $maxAge); } - if ($this->domain != null) { - $cookie = $cookie->withDomain($this->domain); - } + $cookie = $cookie->withDomain($this->domain); // Explicitly set SameSite value, use sensible default if no value provided $cookie = $cookie->withSameSite(SameSite::{$this->samesite ?? 'lax'}()); diff --git a/framework/core/src/Install/Prerequisite/WritablePaths.php b/framework/core/src/Install/Prerequisite/WritablePaths.php index 731bb56059..03af1281f6 100644 --- a/framework/core/src/Install/Prerequisite/WritablePaths.php +++ b/framework/core/src/Install/Prerequisite/WritablePaths.php @@ -61,10 +61,10 @@ private function getAbsolutePath(string $path): string $absolutes = []; foreach ($parts as $part) { - if ($part == '.') { + if ($part === '.') { continue; } - if ($part == '..') { + if ($part === '..') { array_pop($absolutes); } else { $absolutes[] = $part; diff --git a/framework/core/src/Install/Steps/EnableBundledExtensions.php b/framework/core/src/Install/Steps/EnableBundledExtensions.php index 1730b2964b..8c13d03226 100644 --- a/framework/core/src/Install/Steps/EnableBundledExtensions.php +++ b/framework/core/src/Install/Steps/EnableBundledExtensions.php @@ -94,7 +94,7 @@ private function loadExtensions(): Collection $installedExtensions = (new Collection($installed)) ->filter(function ($package) { - return Arr::get($package, 'type') == 'flarum-extension'; + return Arr::get($package, 'type') === 'flarum-extension'; })->filter(function ($package) { return ! empty(Arr::get($package, 'name')); })->map(function ($package) { From 2464caffab4c6c1dee60ef34febec8247bb291f8 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:26:33 +0100 Subject: [PATCH 39/40] refactor: add missing property types --- framework/core/src/Frontend/Compiler/Concerns/HasSources.php | 2 +- framework/core/src/User/User.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Frontend/Compiler/Concerns/HasSources.php b/framework/core/src/Frontend/Compiler/Concerns/HasSources.php index 4f1c9f504e..6dd387307d 100644 --- a/framework/core/src/Frontend/Compiler/Concerns/HasSources.php +++ b/framework/core/src/Frontend/Compiler/Concerns/HasSources.php @@ -20,7 +20,7 @@ trait HasSources /** * @var callable[] */ - protected $sourcesCallbacks = []; + protected array $sourcesCallbacks = []; public function addSources(callable $callback): void { diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index e372bd7b5f..8e25119558 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -87,7 +87,7 @@ class User extends AbstractModel * * @var string[]|null */ - protected $permissions = null; + protected ?array $permissions = null; /** * An array of callables, through each of which the user's list of groups is passed From a6f313b27b39a8044f110529c4dc6f68c49239d2 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:45:23 +0100 Subject: [PATCH 40/40] style: fix formatting for styleci --- .../Api/Endpoint/Concerns/ExtractsListingParams.php | 2 +- framework/core/src/Frontend/Content/CorePayload.php | 4 ++-- .../src/Http/Middleware/CheckForMaintenanceMode.php | 2 +- framework/core/src/Install/AdminUser.php | 4 ++-- framework/core/src/Install/DatabaseConfig.php | 12 ++++++------ .../core/src/Install/Steps/ConnectToDatabase.php | 4 ++-- framework/core/src/Install/Steps/CreateAdminUser.php | 2 +- framework/core/src/Install/Steps/RunMigrations.php | 4 ++-- framework/core/src/Install/Steps/StoreConfig.php | 6 +++--- framework/core/src/Install/Steps/WriteSettings.php | 2 +- framework/core/src/Post/PostRepository.php | 2 +- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php b/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php index e3d483c817..e0609fdf46 100644 --- a/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php +++ b/framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php @@ -103,7 +103,7 @@ public function defaultExtracts(Context $context): array return [ 'filter' => RequestUtil::extractFilter($context->request), 'sort' => RequestUtil::extractSort($context->request, $this->defaultSort, $this->getAvailableSorts($context)), - 'limit' => $limit = (RequestUtil::extractLimit($context->request, $this->limit, $this->maxLimit)), + 'limit' => $limit = RequestUtil::extractLimit($context->request, $this->limit, $this->maxLimit), 'offset' => RequestUtil::extractOffset($context->request, $limit), ]; } diff --git a/framework/core/src/Frontend/Content/CorePayload.php b/framework/core/src/Frontend/Content/CorePayload.php index 67f95de101..2e8c818c90 100644 --- a/framework/core/src/Frontend/Content/CorePayload.php +++ b/framework/core/src/Frontend/Content/CorePayload.php @@ -20,8 +20,8 @@ readonly class CorePayload { public function __construct( - private LocaleManager $locales, - private MaintenanceMode $maintenance, + private LocaleManager $locales, + private MaintenanceMode $maintenance, private SettingsRepositoryInterface $settings ) { } diff --git a/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php b/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php index 29157b5834..f8445ea7d9 100644 --- a/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php +++ b/framework/core/src/Http/Middleware/CheckForMaintenanceMode.php @@ -21,7 +21,7 @@ { public function __construct( private MaintenanceMode $maintenance, - private array $exemptRoutes, + private array $exemptRoutes, ) { } diff --git a/framework/core/src/Install/AdminUser.php b/framework/core/src/Install/AdminUser.php index 3712ca08c9..1861d4e162 100644 --- a/framework/core/src/Install/AdminUser.php +++ b/framework/core/src/Install/AdminUser.php @@ -15,9 +15,9 @@ readonly class AdminUser { public function __construct( - private string $username, + private string $username, #[\SensitiveParameter] private string $password, - private string $email + private string $email ) { $this->validate(); } diff --git a/framework/core/src/Install/DatabaseConfig.php b/framework/core/src/Install/DatabaseConfig.php index 5d1b8ea3ff..bf7b39fe3d 100644 --- a/framework/core/src/Install/DatabaseConfig.php +++ b/framework/core/src/Install/DatabaseConfig.php @@ -15,13 +15,13 @@ class DatabaseConfig implements Arrayable { public function __construct( - private readonly string $driver, - private readonly ?string $host, - private readonly int $port, - private string $database, - private readonly ?string $username, + private readonly string $driver, + private readonly ?string $host, + private readonly int $port, + private string $database, + private readonly ?string $username, #[\SensitiveParameter] private readonly ?string $password, - private readonly ?string $prefix + private readonly ?string $prefix ) { $this->validate(); } diff --git a/framework/core/src/Install/Steps/ConnectToDatabase.php b/framework/core/src/Install/Steps/ConnectToDatabase.php index 9511432d96..779458111e 100644 --- a/framework/core/src/Install/Steps/ConnectToDatabase.php +++ b/framework/core/src/Install/Steps/ConnectToDatabase.php @@ -28,8 +28,8 @@ { public function __construct( private DatabaseConfig $dbConfig, - private Closure $store, - private string $basePath + private Closure $store, + private string $basePath ) { } diff --git a/framework/core/src/Install/Steps/CreateAdminUser.php b/framework/core/src/Install/Steps/CreateAdminUser.php index d44e01a11f..32c8446af5 100644 --- a/framework/core/src/Install/Steps/CreateAdminUser.php +++ b/framework/core/src/Install/Steps/CreateAdminUser.php @@ -19,7 +19,7 @@ { public function __construct( private ConnectionInterface $database, - private AdminUser $admin, + private AdminUser $admin, #[\SensitiveParameter] private ?string $accessToken = null ) { } diff --git a/framework/core/src/Install/Steps/RunMigrations.php b/framework/core/src/Install/Steps/RunMigrations.php index 5d306c54c5..da78d065c1 100644 --- a/framework/core/src/Install/Steps/RunMigrations.php +++ b/framework/core/src/Install/Steps/RunMigrations.php @@ -19,8 +19,8 @@ { public function __construct( private ConnectionInterface $database, - private string $driver, - private string $path + private string $driver, + private string $path ) { } diff --git a/framework/core/src/Install/Steps/StoreConfig.php b/framework/core/src/Install/Steps/StoreConfig.php index cd5cf82d8b..d3709994de 100644 --- a/framework/core/src/Install/Steps/StoreConfig.php +++ b/framework/core/src/Install/Steps/StoreConfig.php @@ -16,10 +16,10 @@ readonly class StoreConfig implements ReversibleStep { public function __construct( - private bool $debugMode, + private bool $debugMode, private DatabaseConfig $dbConfig, - private BaseUrl $baseUrl, - private string $configFile + private BaseUrl $baseUrl, + private string $configFile ) { } diff --git a/framework/core/src/Install/Steps/WriteSettings.php b/framework/core/src/Install/Steps/WriteSettings.php index 2c12ce5da6..e85b2fd0d6 100644 --- a/framework/core/src/Install/Steps/WriteSettings.php +++ b/framework/core/src/Install/Steps/WriteSettings.php @@ -18,7 +18,7 @@ { public function __construct( private ConnectionInterface $database, - private array $custom + private array $custom ) { } diff --git a/framework/core/src/Post/PostRepository.php b/framework/core/src/Post/PostRepository.php index fdd47d29d5..af2c824301 100644 --- a/framework/core/src/Post/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -100,7 +100,7 @@ public function getIndexForNumber(int $discussionId, int $number, ?User $actor = // We don't add $number as a binding because for some // reason doing so makes the bindings go out of order. - ->orderByRaw('ABS(CAST(number AS SIGNED) - '. $number .')'); + ->orderByRaw('ABS(CAST(number AS SIGNED) - '.$number.')'); }); return $query->count();