diff --git a/framework/core/src/Api/ApiKey.php b/framework/core/src/Api/ApiKey.php index e6415df2b..baae2c01e 100644 --- a/framework/core/src/Api/ApiKey.php +++ b/framework/core/src/Api/ApiKey.php @@ -37,10 +37,8 @@ class ApiKey extends AbstractModel */ public static function generate() { - $key = new static; - - $key->id = str_random(40); - - return $key; + return new static([ + 'id' => str_random(40) + ]); } } diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index 15477df4c..926d994c6 100755 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -299,7 +299,7 @@ class Migrator /** * Get the migration repository instance. * - * @return \Illuminate\Database\Migrations\MigrationRepositoryInterface + * @return MigrationRepositoryInterface */ public function getRepository() { diff --git a/framework/core/src/Discussion/Command/StartDiscussionHandler.php b/framework/core/src/Discussion/Command/StartDiscussionHandler.php index 01f99b832..c7399210a 100644 --- a/framework/core/src/Discussion/Command/StartDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/StartDiscussionHandler.php @@ -16,6 +16,7 @@ use Flarum\Discussion\Discussion; use Flarum\Discussion\DiscussionValidator; use Flarum\Discussion\Event\Saving; use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Post\Command\PostReply; use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher; use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; diff --git a/framework/core/src/Discussion/DiscussionServiceProvider.php b/framework/core/src/Discussion/DiscussionServiceProvider.php index 5f8ca4216..e1c0c466a 100644 --- a/framework/core/src/Discussion/DiscussionServiceProvider.php +++ b/framework/core/src/Discussion/DiscussionServiceProvider.php @@ -22,8 +22,8 @@ class DiscussionServiceProvider extends AbstractServiceProvider { $events = $this->app->make('events'); - $events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater'); - $events->subscribe('Flarum\Discussion\DiscussionPolicy'); - $events->subscribe('Flarum\Discussion\DiscussionRenamedLogger'); + $events->subscribe(DiscussionMetadataUpdater::class); + $events->subscribe(DiscussionPolicy::class); + $events->subscribe(DiscussionRenamedLogger::class); } } diff --git a/framework/core/src/Discussion/Search/DiscussionSearcher.php b/framework/core/src/Discussion/Search/DiscussionSearcher.php index 5628dcf2f..c3b5fdb59 100644 --- a/framework/core/src/Discussion/Search/DiscussionSearcher.php +++ b/framework/core/src/Discussion/Search/DiscussionSearcher.php @@ -17,6 +17,8 @@ use Flarum\Discussion\Event\Searching; use Flarum\Post\PostRepository; use Flarum\Search\ApplySearchParametersTrait; use Flarum\Search\GambitManager; +use Flarum\Search\SearchCriteria; +use Flarum\Search\SearchResults; use Illuminate\Database\Eloquent\Collection; /** @@ -58,13 +60,13 @@ class DiscussionSearcher } /** - * @param \Flarum\Search\SearchCriteria $criteria + * @param SearchCriteria $criteria * @param int|null $limit * @param int $offset * @param array $load An array of relationships to load on the results. - * @return \Flarum\Search\SearchResults + * @return SearchResults */ - public function search(\Flarum\Search\SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) + public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) { $actor = $criteria->actor; @@ -107,7 +109,7 @@ class DiscussionSearcher Discussion::setStateUser($actor); $discussions->load($load); - return new \Flarum\Search\SearchResults($discussions, $areMoreResults); + return new SearchResults($discussions, $areMoreResults); } /** diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index 481893f91..a8df0651c 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -14,6 +14,7 @@ namespace Flarum\Discussion; use Flarum\Database\AbstractModel; use Flarum\Discussion\Event\UserRead; use Flarum\Foundation\EventGeneratorTrait; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** @@ -70,7 +71,7 @@ class UserState extends AbstractModel */ public function discussion() { - return $this->belongsTo('Flarum\Discussion\Discussion', 'discussion_id'); + return $this->belongsTo(Discussion::class, 'discussion_id'); } /** @@ -80,7 +81,7 @@ class UserState extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User\User', 'user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** diff --git a/framework/core/src/Event/AbstractConfigureRoutes.php b/framework/core/src/Event/AbstractConfigureRoutes.php index c09ab958c..3ce06cf61 100644 --- a/framework/core/src/Event/AbstractConfigureRoutes.php +++ b/framework/core/src/Event/AbstractConfigureRoutes.php @@ -84,15 +84,6 @@ abstract class AbstractConfigureRoutes */ protected function route($method, $url, $name, $controller) { - $this->routes->$method($url, $name, $this->toController($controller)); - } - - /** - * @param string $controller - * @return callable - */ - protected function toController($controller) - { - return $this->route->toController($controller); + $this->routes->$method($url, $name, $this->route->toController($controller)); } } diff --git a/framework/core/src/Event/ConfigureForumRoutes.php b/framework/core/src/Event/ConfigureForumRoutes.php index d2beb7e0e..934f27a48 100644 --- a/framework/core/src/Event/ConfigureForumRoutes.php +++ b/framework/core/src/Event/ConfigureForumRoutes.php @@ -11,6 +11,8 @@ namespace Flarum\Event; +use Flarum\Forum\Controller\FrontendController; + /** * Configure forum routes. * @@ -21,7 +23,7 @@ class ConfigureForumRoutes extends AbstractConfigureRoutes /** * {@inheritdoc} */ - public function get($url, $name, $handler = 'Flarum\Forum\Controller\WebAppController') + public function get($url, $name, $handler = FrontendController::class) { parent::get($url, $name, $handler); } diff --git a/framework/core/src/Extension/DefaultLanguagePackGuard.php b/framework/core/src/Extension/DefaultLanguagePackGuard.php index 68afffd91..3ec124edc 100644 --- a/framework/core/src/Extension/DefaultLanguagePackGuard.php +++ b/framework/core/src/Extension/DefaultLanguagePackGuard.php @@ -11,7 +11,7 @@ namespace Flarum\Extension; -use Flarum\Event\ExtensionWillBeDisabled; +use Flarum\Extension\Event\Disabling; use Flarum\Http\Exception\ForbiddenException; use Illuminate\Contracts\Events\Dispatcher; @@ -22,14 +22,14 @@ class DefaultLanguagePackGuard */ public function subscribe(Dispatcher $events) { - $events->listen(ExtensionWillBeDisabled::class, [$this, 'whenExtensionWillBeDisabled']); + $events->listen(Disabling::class, [$this, 'whenExtensionWillBeDisabled']); } /** - * @param ExtensionWillBeDisabled $event + * @param Disabling $event * @throws ForbiddenException */ - public function whenExtensionWillBeDisabled(ExtensionWillBeDisabled $event) + public function whenExtensionWillBeDisabled(Disabling $event) { if (in_array('flarum-locale', $event->extension->extra)) { $default_locale = $this->app->make('flarum.settings')->get('default_locale'); diff --git a/framework/core/src/Formatter/FormatterServiceProvider.php b/framework/core/src/Formatter/FormatterServiceProvider.php index de07468dd..25de9fe55 100644 --- a/framework/core/src/Formatter/FormatterServiceProvider.php +++ b/framework/core/src/Formatter/FormatterServiceProvider.php @@ -41,7 +41,7 @@ class FormatterServiceProvider extends AbstractServiceProvider ); }); - $this->app->alias('flarum.formatter', 'Flarum\Formatter\Formatter'); + $this->app->alias('flarum.formatter', Formatter::class); } public function flushFormatter() diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index 216f72961..a71fc436c 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -22,7 +22,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; class DiscussionController extends FrontendController { /** - * @var ApiClient + * @var Client */ protected $api; diff --git a/framework/core/src/Forum/Controller/RegisterController.php b/framework/core/src/Forum/Controller/RegisterController.php index 58f392f15..9a83610ea 100644 --- a/framework/core/src/Forum/Controller/RegisterController.php +++ b/framework/core/src/Forum/Controller/RegisterController.php @@ -12,6 +12,7 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; +use Flarum\Api\Controller\CreateUserController; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; @@ -53,7 +54,7 @@ class RegisterController implements ControllerInterface */ public function handle(Request $request) { - $controller = 'Flarum\Api\Controller\CreateUserController'; + $controller = CreateUserController::class; $actor = $request->getAttribute('actor'); $body = ['data' => ['attributes' => $request->getParsedBody()]]; diff --git a/framework/core/src/Frontend/Event/Rendering.php b/framework/core/src/Frontend/Event/Rendering.php index 6219c557f..a5d81c949 100644 --- a/framework/core/src/Frontend/Event/Rendering.php +++ b/framework/core/src/Frontend/Event/Rendering.php @@ -11,8 +11,8 @@ namespace Flarum\Frontend\Event; -use Flarum\Admin\Controller\FrontendController as AdminWebAppController; -use Flarum\Forum\Controller\FrontendController as ForumWebAppController; +use Flarum\Admin\Controller\FrontendController as AdminFrontendController; +use Flarum\Forum\Controller\FrontendController as ForumFrontendController; use Flarum\Frontend\AbstractFrontendController; use Flarum\Frontend\FrontendView; use Psr\Http\Message\ServerRequestInterface; @@ -48,12 +48,12 @@ class Rendering public function isForum() { - return $this->controller instanceof ForumWebAppController; + return $this->controller instanceof ForumFrontendController; } public function isAdmin() { - return $this->controller instanceof AdminWebAppController; + return $this->controller instanceof AdminFrontendController; } public function addAssets($files) diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index 4af4a4d61..14daf1b69 100755 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -15,8 +15,9 @@ use Flarum\Database\AbstractModel; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Group\Event\Created; -use Flarum\Group\Event\Deleting; +use Flarum\Group\Event\Deleted; use Flarum\Group\Event\Renamed; +use Flarum\User\User; /** * @property int $id @@ -67,7 +68,7 @@ class Group extends AbstractModel parent::boot(); static::deleted(function (Group $group) { - $group->raise(new Deleting($group)); + $group->raise(new Deleted($group)); $group->permissions()->delete(); }); @@ -120,7 +121,7 @@ class Group extends AbstractModel */ public function users() { - return $this->belongsToMany('Flarum\User\User', 'users_groups'); + return $this->belongsToMany(User::class, 'users_groups'); } /** @@ -130,6 +131,6 @@ class Group extends AbstractModel */ public function permissions() { - return $this->hasMany('Flarum\Group\Permission'); + return $this->hasMany(Permission::class); } } diff --git a/framework/core/src/Group/GroupServiceProvider.php b/framework/core/src/Group/GroupServiceProvider.php index bdf1ceb15..ad923df9f 100644 --- a/framework/core/src/Group/GroupServiceProvider.php +++ b/framework/core/src/Group/GroupServiceProvider.php @@ -21,6 +21,6 @@ class GroupServiceProvider extends AbstractServiceProvider public function boot() { $events = $this->app->make('events'); - $events->subscribe('Flarum\Group\GroupPolicy'); + $events->subscribe(GroupPolicy::class); } } diff --git a/framework/core/src/Group/Permission.php b/framework/core/src/Group/Permission.php index 0ed470e3b..110c365b0 100755 --- a/framework/core/src/Group/Permission.php +++ b/framework/core/src/Group/Permission.php @@ -31,7 +31,7 @@ class Permission extends AbstractModel */ public function group() { - return $this->belongsTo('Flarum\Group\Group', 'group_id'); + return $this->belongsTo(Group::class, 'group_id'); } /** diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index f7f9d3a98..1255e6216 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -14,14 +14,29 @@ namespace Flarum\Install\Console; use Exception; use Flarum\Console\AbstractCommand; use Flarum\Database\AbstractModel; +use Flarum\Database\Migrator; +use Flarum\Discussion\DiscussionServiceProvider; +use Flarum\Extension\ExtensionManager; +use Flarum\Formatter\FormatterServiceProvider; use Flarum\Group\Group; +use Flarum\Group\GroupServiceProvider; use Flarum\Group\Permission; +use Flarum\Install\Prerequisite\PrerequisiteInterface; +use Flarum\Notification\NotificationServiceProvider; +use Flarum\Post\PostServiceProvider; +use Flarum\Search\SearchServiceProvider; +use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\User; +use Flarum\User\UserServiceProvider; use Illuminate\Contracts\Foundation\Application; +use Illuminate\Database\ConnectionInterface; +use Illuminate\Database\ConnectionResolverInterface; +use Illuminate\Database\Schema\Builder; use Illuminate\Filesystem\Filesystem; use Illuminate\Validation\Factory; use PDO; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Translation\TranslatorInterface; class InstallCommand extends AbstractCommand { @@ -163,7 +178,7 @@ class InstallCommand extends AbstractCommand $this->storeConfiguration(); - $resolver = $this->application->make('Illuminate\Database\ConnectionResolverInterface'); + $resolver = $this->application->make(ConnectionResolverInterface::class); AbstractModel::setConnectionResolver($resolver); AbstractModel::setEventDispatcher($this->application->make('events')); @@ -171,13 +186,13 @@ class InstallCommand extends AbstractCommand $this->writeSettings(); - $this->application->register('Flarum\Formatter\FormatterServiceProvider'); - $this->application->register('Flarum\Discussion\DiscussionServiceProvider'); - $this->application->register('Flarum\Group\GroupServiceProvider'); - $this->application->register('Flarum\Notification\NotificationServiceProvider'); - $this->application->register('Flarum\Search\SearchServiceProvider'); - $this->application->register('Flarum\Post\PostServiceProvider'); - $this->application->register('Flarum\User\UserServiceProvider'); + $this->application->register(FormatterServiceProvider::class); + $this->application->register(DiscussionServiceProvider::class); + $this->application->register(GroupServiceProvider::class); + $this->application->register(NotificationServiceProvider::class); + $this->application->register(SearchServiceProvider::class); + $this->application->register(PostServiceProvider::class); + $this->application->register(UserServiceProvider::class); $this->seedGroups(); $this->seedPermissions(); @@ -240,11 +255,11 @@ class InstallCommand extends AbstractCommand protected function runMigrations() { - $this->application->bind('Illuminate\Database\Schema\Builder', function ($container) { - return $container->make('Illuminate\Database\ConnectionInterface')->getSchemaBuilder(); + $this->application->bind(Builder::class, function ($container) { + return $container->make(ConnectionInterface::class)->getSchemaBuilder(); }); - $migrator = $this->application->make('Flarum\Database\Migrator'); + $migrator = $this->application->make(Migrator::class); $migrator->getRepository()->createRepository(); $migrator->run(__DIR__.'/../../../migrations'); @@ -256,7 +271,7 @@ class InstallCommand extends AbstractCommand protected function writeSettings() { - $settings = $this->application->make('Flarum\Settings\SettingsRepositoryInterface'); + $settings = $this->application->make(SettingsRepositoryInterface::class); $this->info('Writing default settings'); @@ -341,7 +356,7 @@ class InstallCommand extends AbstractCommand protected function enableBundledExtensions() { - $extensions = $this->application->make('Flarum\Extension\ExtensionManager'); + $extensions = $this->application->make(ExtensionManager::class); $migrator = $extensions->getMigrator(); @@ -386,7 +401,7 @@ class InstallCommand extends AbstractCommand */ protected function getPrerequisites() { - return $this->application->make('Flarum\Install\Prerequisite\PrerequisiteInterface'); + return $this->application->make(PrerequisiteInterface::class); } /** @@ -394,7 +409,7 @@ class InstallCommand extends AbstractCommand */ protected function getValidator() { - return new Factory($this->application->make('Symfony\Component\Translation\TranslatorInterface')); + return new Factory($this->application->make(TranslatorInterface::class)); } protected function showErrors($errors) diff --git a/framework/core/src/Install/Controller/IndexController.php b/framework/core/src/Install/Controller/IndexController.php index 680b647b0..e96110969 100644 --- a/framework/core/src/Install/Controller/IndexController.php +++ b/framework/core/src/Install/Controller/IndexController.php @@ -40,7 +40,7 @@ class IndexController extends AbstractHtmlController /** * @param Request $request - * @return \Psr\Http\Message\ResponseInterface + * @return \Illuminate\Contracts\Support\Renderable */ public function render(Request $request) { diff --git a/framework/core/src/Install/InstallServiceProvider.php b/framework/core/src/Install/InstallServiceProvider.php index 733a1ce9e..e57f47ab1 100644 --- a/framework/core/src/Install/InstallServiceProvider.php +++ b/framework/core/src/Install/InstallServiceProvider.php @@ -17,6 +17,7 @@ use Flarum\Http\RouteHandlerFactory; use Flarum\Install\Prerequisite\Composite; use Flarum\Install\Prerequisite\PhpExtensions; use Flarum\Install\Prerequisite\PhpVersion; +use Flarum\Install\Prerequisite\PrerequisiteInterface; use Flarum\Install\Prerequisite\WritablePaths; class InstallServiceProvider extends AbstractServiceProvider @@ -27,7 +28,7 @@ class InstallServiceProvider extends AbstractServiceProvider public function register() { $this->app->bind( - 'Flarum\Install\Prerequisite\PrerequisiteInterface', + PrerequisiteInterface::class, function () { return new Composite( new PhpVersion('5.5.0'), diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 034e21a1c..4ddcc46f5 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -15,6 +15,8 @@ use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Events\Dispatcher; use Symfony\Component\Translation\MessageSelector; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorInterface; class LocaleServiceProvider extends AbstractServiceProvider { @@ -35,8 +37,8 @@ class LocaleServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton('Flarum\Locale\LocaleManager'); - $this->app->alias('Flarum\Locale\LocaleManager', 'flarum.localeManager'); + $this->app->singleton(LocaleManager::class); + $this->app->alias(LocaleManager::class, 'flarum.localeManager'); $this->app->singleton('translator', function () { $defaultLocale = $this->getDefaultLocale(); @@ -47,8 +49,8 @@ class LocaleServiceProvider extends AbstractServiceProvider return $translator; }); - $this->app->alias('translator', 'Symfony\Component\Translation\Translator'); - $this->app->alias('translator', 'Symfony\Component\Translation\TranslatorInterface'); + $this->app->alias('translator', Translator::class); + $this->app->alias('translator', TranslatorInterface::class); } private function getDefaultLocale() diff --git a/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php index 996483c27..50d2e6146 100644 --- a/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php +++ b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php @@ -11,6 +11,7 @@ namespace Flarum\Notification\Blueprint; +use Flarum\Discussion\Discussion; use Flarum\Post\DiscussionRenamedPost; class DiscussionRenamedBlueprint implements BlueprintInterface @@ -65,6 +66,6 @@ class DiscussionRenamedBlueprint implements BlueprintInterface */ public static function getSubjectModel() { - return 'Flarum\Discussion\Discussion'; + return Discussion::class; } } diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index 6a32fdd36..ad289ca08 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -12,6 +12,7 @@ namespace Flarum\Notification; use Flarum\Database\AbstractModel; +use Flarum\User\User; /** * Models a notification record in the database. @@ -113,7 +114,7 @@ class Notification extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User\User', 'user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** @@ -123,7 +124,7 @@ class Notification extends AbstractModel */ public function sender() { - return $this->belongsTo('Flarum\User\User', 'sender_id'); + return $this->belongsTo(User::class, 'sender_id'); } /** diff --git a/framework/core/src/Notification/NotificationServiceProvider.php b/framework/core/src/Notification/NotificationServiceProvider.php index 3edbffcaa..8771198a0 100644 --- a/framework/core/src/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Notification/NotificationServiceProvider.php @@ -13,6 +13,7 @@ namespace Flarum\Notification; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; use Flarum\User\User; use ReflectionClass; @@ -32,7 +33,7 @@ class NotificationServiceProvider extends AbstractServiceProvider public function registerNotificationTypes() { $blueprints = [ - 'Flarum\Notification\Blueprint\DiscussionRenamedBlueprint' => ['alert'] + DiscussionRenamedBlueprint::class => ['alert'] ]; $this->app->make('events')->fire( @@ -51,7 +52,7 @@ class NotificationServiceProvider extends AbstractServiceProvider in_array('alert', $enabled) ); - if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Notification\MailableInterface')) { + if ((new ReflectionClass($blueprint))->implementsInterface(MailableInterface::class)) { User::addPreference( User::getNotificationPreferenceKey($type, 'email'), 'boolval',