From 0ca4e1ab7b6cc9685f97d5c2ea9851d348eaeea0 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 19 May 2015 01:03:12 +0200 Subject: [PATCH] Fix coding standards to conform to PSR-2 --- .../core/src/Api/Actions/Posts/GetsPosts.php | 6 +- .../src/Console/ConsoleServiceProvider.php | 1 - framework/core/src/Console/InstallCommand.php | 106 ++++++++--------- framework/core/src/Console/SeedCommand.php | 110 +++++++++--------- .../core/src/Core/CoreServiceProvider.php | 2 +- .../core/src/Core/Extensions/Extension.php | 1 - .../src/Core/Extensions/ExtensionManager.php | 1 - .../src/Core/Formatter/FormatterManager.php | 64 +++++----- .../src/Core/Formatter/LinkifyFormatter.php | 8 +- .../Events/EmailConfirmationMailer.php | 1 - framework/core/src/Core/Models/Guest.php | 22 ++-- .../Discussions/DiscussionSearchResults.php | 2 +- .../core/src/Core/Search/GambitAbstract.php | 4 +- .../core/src/Core/Search/GambitManager.php | 7 +- .../Core/Search/Users/UserSearchResults.php | 2 +- .../src/Core/Seeders/ConfigTableSeeder.php | 22 ++-- .../Core/Seeders/DiscussionsTableSeeder.php | 1 - .../src/Core/Seeders/GroupsTableSeeder.php | 22 ++-- .../Core/Seeders/PermissionsTableSeeder.php | 22 ++-- .../src/Core/Seeders/UsersTableSeeder.php | 8 +- .../core/src/Core/Support/MappedMorphTo.php | 65 ++++++----- .../Extensions/ExtensionsServiceProvider.php | 4 +- 22 files changed, 239 insertions(+), 242 deletions(-) diff --git a/framework/core/src/Api/Actions/Posts/GetsPosts.php b/framework/core/src/Api/Actions/Posts/GetsPosts.php index ae19b910a..d1a458308 100644 --- a/framework/core/src/Api/Actions/Posts/GetsPosts.php +++ b/framework/core/src/Api/Actions/Posts/GetsPosts.php @@ -4,8 +4,8 @@ use Flarum\Api\JsonApiRequest; trait GetsPosts { - protected function getPosts(JsonApiRequest $request, array $where) - { + protected function getPosts(JsonApiRequest $request, array $where) + { $user = $request->actor->getUser(); if (isset($where['discussion_id']) && ($near = $request->get('near')) > 1) { @@ -22,5 +22,5 @@ trait GetsPosts $request->limit, $offset ); - } + } } diff --git a/framework/core/src/Console/ConsoleServiceProvider.php b/framework/core/src/Console/ConsoleServiceProvider.php index 84693ebee..4d0eafb41 100644 --- a/framework/core/src/Console/ConsoleServiceProvider.php +++ b/framework/core/src/Console/ConsoleServiceProvider.php @@ -17,6 +17,5 @@ class ConsoleServiceProvider extends ServiceProvider public function register() { - } } diff --git a/framework/core/src/Console/InstallCommand.php b/framework/core/src/Console/InstallCommand.php index e236e0dcc..d709e8013 100644 --- a/framework/core/src/Console/InstallCommand.php +++ b/framework/core/src/Console/InstallCommand.php @@ -5,41 +5,42 @@ use Illuminate\Foundation\Application; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; -class InstallCommand extends Command { +class InstallCommand extends Command +{ - /** - * The console command name. - * - * @var string - */ - protected $name = 'flarum:install'; + /** + * The console command name. + * + * @var string + */ + protected $name = 'flarum:install'; - /** - * The console command description. - * - * @var string - */ - protected $description = 'Run Flarum\'s installation migrations and seeds.'; + /** + * The console command description. + * + * @var string + */ + protected $description = 'Run Flarum\'s installation migrations and seeds.'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct(Application $app) - { - parent::__construct(); + /** + * Create a new command instance. + * + * @return void + */ + public function __construct(Application $app) + { + parent::__construct(); $this->app = $app; - } + } - /** - * Execute the console command. - * - * @return mixed - */ - public function fire() - { + /** + * Execute the console command. + * + * @return mixed + */ + public function fire() + { $path = str_replace($this->laravel['path.base'].'/', '', __DIR__.'/../../migrations'); $this->call('migrate', ['--path' => $path]); @@ -50,30 +51,29 @@ class InstallCommand extends Command { // Create config file so that we know Flarum is installed copy(base_path('../config.example.php'), base_path('../config.php')); - } + } - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - // ['example', InputArgument::REQUIRED, 'An example argument.'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - // ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null], - ]; - } + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return [ + // ['example', InputArgument::REQUIRED, 'An example argument.'], + ]; + } + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + // ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null], + ]; + } } diff --git a/framework/core/src/Console/SeedCommand.php b/framework/core/src/Console/SeedCommand.php index cd97ff959..f8db5eee4 100644 --- a/framework/core/src/Console/SeedCommand.php +++ b/framework/core/src/Console/SeedCommand.php @@ -5,67 +5,67 @@ use Illuminate\Foundation\Application; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; -class SeedCommand extends Command { +class SeedCommand extends Command +{ - /** - * The console command name. - * - * @var string - */ - protected $name = 'flarum:seed'; + /** + * The console command name. + * + * @var string + */ + protected $name = 'flarum:seed'; - /** - * The console command description. - * - * @var string - */ - protected $description = 'Seed Flarum\'s database with fake data.'; + /** + * The console command description. + * + * @var string + */ + protected $description = 'Seed Flarum\'s database with fake data.'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct(Application $app) - { - parent::__construct(); + /** + * Create a new command instance. + * + * @return void + */ + public function __construct(Application $app) + { + parent::__construct(); $this->app = $app; - } + } - /** - * Execute the console command. - * - * @return mixed - */ - public function fire() - { - $this->call('db:seed', ['--class' => 'Flarum\Core\Seeders\DiscussionsTableSeeder']); - $this->call('db:seed', ['--class' => 'Flarum\Core\Seeders\UsersTableSeeder']); - } + /** + * Execute the console command. + * + * @return mixed + */ + public function fire() + { + $this->call('db:seed', ['--class' => 'Flarum\Core\Seeders\DiscussionsTableSeeder']); + $this->call('db:seed', ['--class' => 'Flarum\Core\Seeders\UsersTableSeeder']); + } - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - // ['example', InputArgument::REQUIRED, 'An example argument.'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - // ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null], - ]; - } + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return [ + // ['example', InputArgument::REQUIRED, 'An example argument.'], + ]; + } + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + // ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null], + ]; + } } diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index f5cedf678..8248c3a5a 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -78,7 +78,7 @@ class CoreServiceProvider extends ServiceProvider $this->app->when('Flarum\Core\Handlers\Commands\UploadAvatarCommandHandler') ->needs('League\Flysystem\FilesystemInterface') - ->give(function(Container $app) { + ->give(function (Container $app) { return $app->make('Illuminate\Contracts\Filesystem\Factory')->disk('flarum-avatars')->getDriver(); }); } diff --git a/framework/core/src/Core/Extensions/Extension.php b/framework/core/src/Core/Extensions/Extension.php index 08424b495..3e51530cf 100755 --- a/framework/core/src/Core/Extensions/Extension.php +++ b/framework/core/src/Core/Extensions/Extension.php @@ -2,5 +2,4 @@ class Extension { - } diff --git a/framework/core/src/Core/Extensions/ExtensionManager.php b/framework/core/src/Core/Extensions/ExtensionManager.php index e8d44a714..e40583a26 100755 --- a/framework/core/src/Core/Extensions/ExtensionManager.php +++ b/framework/core/src/Core/Extensions/ExtensionManager.php @@ -2,5 +2,4 @@ class ExtensionManager { - } diff --git a/framework/core/src/Core/Formatter/FormatterManager.php b/framework/core/src/Core/Formatter/FormatterManager.php index 4e746fff0..0c6c55fc0 100644 --- a/framework/core/src/Core/Formatter/FormatterManager.php +++ b/framework/core/src/Core/Formatter/FormatterManager.php @@ -4,35 +4,35 @@ use Illuminate\Container\Container; class FormatterManager { - protected $formatters = []; + protected $formatters = []; - /** - * The IoC container instance. - * - * @var \Illuminate\Container\Container - */ - protected $container; + /** + * The IoC container instance. + * + * @var \Illuminate\Container\Container + */ + protected $container; - /** - * Create a new formatter manager instance. - * - * @param \Illuminate\Container\Container $container - * @return void - */ - public function __construct(Container $container = null) - { - $this->container = $container ?: new Container; - } + /** + * Create a new formatter manager instance. + * + * @param \Illuminate\Container\Container $container + * @return void + */ + public function __construct(Container $container = null) + { + $this->container = $container ?: new Container; + } - public function add($name, $formatter, $priority = 0) - { - $this->formatters[$name] = [$formatter, $priority]; - } + public function add($name, $formatter, $priority = 0) + { + $this->formatters[$name] = [$formatter, $priority]; + } - public function remove($name) - { - unset($this->formatters[$name]); - } + public function remove($name) + { + unset($this->formatters[$name]); + } protected function getFormatters() { @@ -54,14 +54,14 @@ class FormatterManager return $result; } - public function format($text, $post = null) - { - foreach ($this->getFormatters() as $formatter) { - $text = $this->container->make($formatter)->format($text, $post); - } + public function format($text, $post = null) + { + foreach ($this->getFormatters() as $formatter) { + $text = $this->container->make($formatter)->format($text, $post); + } - return $text; - } + return $text; + } public function strip($text) { diff --git a/framework/core/src/Core/Formatter/LinkifyFormatter.php b/framework/core/src/Core/Formatter/LinkifyFormatter.php index 763943d2b..be5570f29 100644 --- a/framework/core/src/Core/Formatter/LinkifyFormatter.php +++ b/framework/core/src/Core/Formatter/LinkifyFormatter.php @@ -11,8 +11,8 @@ class LinkifyFormatter $this->linkify = $linkify; } - public function format($text) - { - return $this->linkify->process($text, ['attr' => ['target' => '_blank']]); - } + public function format($text) + { + return $this->linkify->process($text, ['attr' => ['target' => '_blank']]); + } } diff --git a/framework/core/src/Core/Handlers/Events/EmailConfirmationMailer.php b/framework/core/src/Core/Handlers/Events/EmailConfirmationMailer.php index 8d15a5d2e..4b2b7747e 100755 --- a/framework/core/src/Core/Handlers/Events/EmailConfirmationMailer.php +++ b/framework/core/src/Core/Handlers/Events/EmailConfirmationMailer.php @@ -46,6 +46,5 @@ class EmailConfirmationMailer public function whenEmailWasChanged(EmailWasChanged $event) { - } } diff --git a/framework/core/src/Core/Models/Guest.php b/framework/core/src/Core/Models/Guest.php index 7dc91e052..9ea7e541d 100755 --- a/framework/core/src/Core/Models/Guest.php +++ b/framework/core/src/Core/Models/Guest.php @@ -9,22 +9,22 @@ class Guest extends User * * @return \Flarum\Core\Models\Group */ - public function getGroupsAttribute() - { - if (! isset($this->attributes['groups'])) { - $this->attributes['groups'] = $this->relations['groups'] = Group::where('id', Group::GUEST_ID)->get(); - } + public function getGroupsAttribute() + { + if (! isset($this->attributes['groups'])) { + $this->attributes['groups'] = $this->relations['groups'] = Group::where('id', Group::GUEST_ID)->get(); + } - return $this->attributes['groups']; - } + return $this->attributes['groups']; + } /** * Check whether or not the user is a guest. * * @return boolean */ - public function guest() - { - return true; - } + public function guest() + { + return true; + } } diff --git a/framework/core/src/Core/Search/Discussions/DiscussionSearchResults.php b/framework/core/src/Core/Search/Discussions/DiscussionSearchResults.php index b683b564e..eb974f773 100644 --- a/framework/core/src/Core/Search/Discussions/DiscussionSearchResults.php +++ b/framework/core/src/Core/Search/Discussions/DiscussionSearchResults.php @@ -20,7 +20,7 @@ class DiscussionSearchResults return $this->discussions; } - public function getTotal() + public function getTotal() { return $this->total; } diff --git a/framework/core/src/Core/Search/GambitAbstract.php b/framework/core/src/Core/Search/GambitAbstract.php index 39d91bcd7..ef1f64715 100644 --- a/framework/core/src/Core/Search/GambitAbstract.php +++ b/framework/core/src/Core/Search/GambitAbstract.php @@ -2,7 +2,7 @@ abstract class GambitAbstract { - protected $pattern; + protected $pattern; public function apply($bit, SearcherInterface $searcher) { @@ -12,7 +12,7 @@ abstract class GambitAbstract } } - public function match($bit) + public function match($bit) { if (preg_match('/^'.$this->pattern.'$/i', $bit, $matches)) { return $matches; diff --git a/framework/core/src/Core/Search/GambitManager.php b/framework/core/src/Core/Search/GambitManager.php index 6b91ac599..0d534b1d1 100644 --- a/framework/core/src/Core/Search/GambitManager.php +++ b/framework/core/src/Core/Search/GambitManager.php @@ -20,14 +20,14 @@ class GambitManager $this->gambits[] = $gambit; } - public function apply($string, $searcher) - { + public function apply($string, $searcher) + { $string = $this->applyGambits($string, $searcher); if ($string) { $this->applyFulltext($string, $searcher); } - } + } public function setFulltextGambit($gambit) { @@ -69,5 +69,4 @@ class GambitManager $searcher->addActiveGambit($gambit); $gambit->apply($string, $searcher); } - } diff --git a/framework/core/src/Core/Search/Users/UserSearchResults.php b/framework/core/src/Core/Search/Users/UserSearchResults.php index e033bea7e..6c25282d0 100644 --- a/framework/core/src/Core/Search/Users/UserSearchResults.php +++ b/framework/core/src/Core/Search/Users/UserSearchResults.php @@ -20,7 +20,7 @@ class UserSearchResults return $this->users; } - public function getTotal() + public function getTotal() { return $this->total; } diff --git a/framework/core/src/Core/Seeders/ConfigTableSeeder.php b/framework/core/src/Core/Seeders/ConfigTableSeeder.php index dd829ce8b..68211efb7 100644 --- a/framework/core/src/Core/Seeders/ConfigTableSeeder.php +++ b/framework/core/src/Core/Seeders/ConfigTableSeeder.php @@ -3,15 +3,16 @@ use Illuminate\Database\Seeder; use DB; -class ConfigTableSeeder extends Seeder { +class ConfigTableSeeder extends Seeder +{ - /** - * Run the database seeds. - * - * @return void - */ - public function run() - { + /** + * Run the database seeds. + * + * @return void + */ + public function run() + { $config = [ 'api_url' => 'http://flarum.dev/api', 'base_url' => 'http://flarum.dev', @@ -20,9 +21,8 @@ class ConfigTableSeeder extends Seeder { 'welcome_title' => 'Welcome to Flarum Demo Forum' ]; - DB::table('config')->insert(array_map(function($key, $value) { + DB::table('config')->insert(array_map(function ($key, $value) { return compact('key', 'value'); }, array_keys($config), $config)); - } - + } } diff --git a/framework/core/src/Core/Seeders/DiscussionsTableSeeder.php b/framework/core/src/Core/Seeders/DiscussionsTableSeeder.php index 2537dd530..e26a8b738 100644 --- a/framework/core/src/Core/Seeders/DiscussionsTableSeeder.php +++ b/framework/core/src/Core/Seeders/DiscussionsTableSeeder.php @@ -121,7 +121,6 @@ class DiscussionsTableSeeder extends Seeder 'read_time' => $faker->dateTimeBetween($discussion->start_time, 'now') ]); } catch (\Illuminate\Database\QueryException $e) { - } } } diff --git a/framework/core/src/Core/Seeders/GroupsTableSeeder.php b/framework/core/src/Core/Seeders/GroupsTableSeeder.php index 14b7823f3..eea3bfccf 100644 --- a/framework/core/src/Core/Seeders/GroupsTableSeeder.php +++ b/framework/core/src/Core/Seeders/GroupsTableSeeder.php @@ -3,19 +3,20 @@ use Illuminate\Database\Seeder; use Flarum\Core\Models\Group; -class GroupsTableSeeder extends Seeder { +class GroupsTableSeeder extends Seeder +{ - /** - * Run the database seeds. - * - * @return void - */ - public function run() - { + /** + * Run the database seeds. + * + * @return void + */ + public function run() + { Group::unguard(); Group::truncate(); - $groups = [ + $groups = [ ['Admin', 'Admins', '#B72A2A', 'wrench'], ['Guest', 'Guests', null, null], ['Member', 'Members', null, null], @@ -29,6 +30,5 @@ class GroupsTableSeeder extends Seeder { 'icon' => $group[3] ]); } - } - + } } diff --git a/framework/core/src/Core/Seeders/PermissionsTableSeeder.php b/framework/core/src/Core/Seeders/PermissionsTableSeeder.php index 3fc937391..ae48890d2 100644 --- a/framework/core/src/Core/Seeders/PermissionsTableSeeder.php +++ b/framework/core/src/Core/Seeders/PermissionsTableSeeder.php @@ -3,18 +3,19 @@ use Illuminate\Database\Seeder; use Flarum\Core\Models\Permission; -class PermissionsTableSeeder extends Seeder { +class PermissionsTableSeeder extends Seeder +{ - /** - * Run the database seeds. - * - * @return void - */ - public function run() - { + /** + * Run the database seeds. + * + * @return void + */ + public function run() + { Permission::truncate(); - $permissions = [ + $permissions = [ // Guests can view the forum [2, 'forum.view'], @@ -38,6 +39,5 @@ class PermissionsTableSeeder extends Seeder { ]; } Permission::insert($permissions); - } - + } } diff --git a/framework/core/src/Core/Seeders/UsersTableSeeder.php b/framework/core/src/Core/Seeders/UsersTableSeeder.php index 1b547dc82..3e07d46f4 100644 --- a/framework/core/src/Core/Seeders/UsersTableSeeder.php +++ b/framework/core/src/Core/Seeders/UsersTableSeeder.php @@ -6,10 +6,10 @@ use Flarum\Core\Models\User; class UsersTableSeeder extends Seeder { /** - * Run the database seeds. - * - * @return void - */ + * Run the database seeds. + * + * @return void + */ public function run() { User::unguard(); diff --git a/framework/core/src/Core/Support/MappedMorphTo.php b/framework/core/src/Core/Support/MappedMorphTo.php index f52a418ba..368592d13 100644 --- a/framework/core/src/Core/Support/MappedMorphTo.php +++ b/framework/core/src/Core/Support/MappedMorphTo.php @@ -4,40 +4,41 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; -class MappedMorphTo extends MorphTo { +class MappedMorphTo extends MorphTo +{ - /** - * - * @var string - */ - protected $map; + /** + * + * @var string + */ + protected $map; - /** - * Create a new morph to relationship instance. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Model $parent - * @param string $foreignKey - * @param string $otherKey - * @param string $type - * @param string $relation - * @return void - */ - public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $type, $relation, $map) - { - $this->map = $map; + /** + * Create a new morph to relationship instance. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Model $parent + * @param string $foreignKey + * @param string $otherKey + * @param string $type + * @param string $relation + * @return void + */ + public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $type, $relation, $map) + { + $this->map = $map; - parent::__construct($query, $parent, $foreignKey, $otherKey, $type, $relation); - } + parent::__construct($query, $parent, $foreignKey, $otherKey, $type, $relation); + } - /** - * Create a new model instance by type. - * - * @param string $type - * @return \Illuminate\Database\Eloquent\Model - */ - public function createModelByType($type) - { - return new $this->map[$type]; - } + /** + * Create a new model instance by type. + * + * @param string $type + * @return \Illuminate\Database\Eloquent\Model + */ + public function createModelByType($type) + { + return new $this->map[$type]; + } } diff --git a/framework/core/src/Support/Extensions/ExtensionsServiceProvider.php b/framework/core/src/Support/Extensions/ExtensionsServiceProvider.php index ae5c2838e..41147d85d 100644 --- a/framework/core/src/Support/Extensions/ExtensionsServiceProvider.php +++ b/framework/core/src/Support/Extensions/ExtensionsServiceProvider.php @@ -14,7 +14,9 @@ class ExtensionsServiceProvider extends ServiceProvider public function register() { // Extensions will not be registered if Flarum is not installed yet - if (!Core::isInstalled()) return; + if (!Core::isInstalled()) { + return; + } $extensions = json_decode(DB::table('config')->where('key', 'extensions_enabled')->pluck('value'), true); $providers = [];