Cleanup code, typehints and class references

This commit is contained in:
Franz Liedke 2017-07-02 13:29:30 +02:00
parent 686797cdf3
commit cafb38aa64
23 changed files with 87 additions and 69 deletions

View File

@ -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)
]);
}
}

View File

@ -299,7 +299,7 @@ class Migrator
/**
* Get the migration repository instance.
*
* @return \Illuminate\Database\Migrations\MigrationRepositoryInterface
* @return MigrationRepositoryInterface
*/
public function getRepository()
{

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);
}
/**

View File

@ -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');
}
/**

View File

@ -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));
}
}

View File

@ -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);
}

View File

@ -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');

View File

@ -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()

View File

@ -22,7 +22,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
class DiscussionController extends FrontendController
{
/**
* @var ApiClient
* @var Client
*/
protected $api;

View File

@ -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()]];

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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');
}
/**

View File

@ -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)

View File

@ -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)
{

View File

@ -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'),

View File

@ -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()

View File

@ -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;
}
}

View File

@ -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');
}
/**

View File

@ -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',