Apply fixes from StyleCI (#93)

[ci skip] [skip ci]
This commit is contained in:
Pig Fang 2019-08-15 23:27:29 +08:00 committed by GitHub
parent e67df90978
commit 372c7768d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 44 additions and 22 deletions

View File

@ -34,6 +34,7 @@ class Handler extends ExceptionHandler
}) })
->map(function ($trace) { ->map(function ($trace) {
$trace['file'] = str_replace(base_path().DIRECTORY_SEPARATOR, '', $trace['file']); $trace['file'] = str_replace(base_path().DIRECTORY_SEPARATOR, '', $trace['file']);
return $trace; return $trace;
}) })
->filter(function ($trace) { ->filter(function ($trace) {

View File

@ -7,8 +7,8 @@ use Option;
use Notification; use Notification;
use Carbon\Carbon; use Carbon\Carbon;
use App\Models\User; use App\Models\User;
use App\Notifications;
use App\Models\Player; use App\Models\Player;
use App\Notifications;
use App\Models\Texture; use App\Models\Texture;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Services\OptionForm; use App\Services\OptionForm;
@ -99,6 +99,7 @@ class AdminController extends Controller
Notification::send($users, $notification); Notification::send($users, $notification);
session(['sentResult' => trans('admin.notifications.send.success')]); session(['sentResult' => trans('admin.notifications.send.success')]);
return redirect('/admin'); return redirect('/admin');
} }

View File

@ -63,6 +63,7 @@ class MarketController extends Controller
$pluginsHaveUpdate = collect($this->getAllAvailablePlugins()) $pluginsHaveUpdate = collect($this->getAllAvailablePlugins())
->filter(function ($item) use ($manager) { ->filter(function ($item) use ($manager) {
$plugin = $manager->get($item['name']); $plugin = $manager->get($item['name']);
return $plugin && Comparator::greaterThan($item['version'], $plugin->version); return $plugin && Comparator::greaterThan($item['version'], $plugin->version);
}); });

View File

@ -114,6 +114,7 @@ class ReportController extends Controller
self::returnScore($report); self::returnScore($report);
$report->status = Report::RESOLVED; $report->status = Report::RESOLVED;
$report->save(); $report->save();
return json(trans('general.texture-deleted'), 0, ['status' => Report::RESOLVED]); return json(trans('general.texture-deleted'), 0, ['status' => Report::RESOLVED]);
} }
break; break;
@ -138,13 +139,16 @@ class ReportController extends Controller
return json(trans('general.op-success'), 0, ['status' => Report::RESOLVED]); return json(trans('general.op-success'), 0, ['status' => Report::RESOLVED]);
} }
static function returnScore($report) { public static function returnScore($report)
{
if ($report->status == Report::PENDING && ($score = option('reporter_score_modification', 0)) < 0) { if ($report->status == Report::PENDING && ($score = option('reporter_score_modification', 0)) < 0) {
$report->informer->score -= $score; $report->informer->score -= $score;
$report->informer->save(); $report->informer->save();
} }
} }
static function giveAward($report) {
public static function giveAward($report)
{
if ($report->status == Report::PENDING) { if ($report->status == Report::PENDING) {
$report->informer->score += option('reporter_reward_score', 0); $report->informer->score += option('reporter_reward_score', 0);
$report->informer->save(); $report->informer->save();

View File

@ -149,8 +149,8 @@ class SetupController extends Controller
'--force' => true, '--force' => true,
'--path' => [ '--path' => [
'database/migrations', 'database/migrations',
'vendor/laravel/passport/database/migrations' 'vendor/laravel/passport/database/migrations',
] ],
]); ]);
Log::info('[SetupWizard] Tables migrated.'); Log::info('[SetupWizard] Tables migrated.');

View File

@ -96,6 +96,7 @@ class UpdateController extends Controller
$php = Arr::get($this->info, 'php'); $php = Arr::get($this->info, 'php');
if (Comparator::lessThan(PHP_VERSION, $php)) { if (Comparator::lessThan(PHP_VERSION, $php)) {
$this->error = trans('admin.update.errors.php', ['version' => $php]); $this->error = trans('admin.update.errors.php', ['version' => $php]);
return false; return false;
} }

View File

@ -10,6 +10,7 @@ class LockUpdatePage
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
abort_if($request->user()->permission < User::SUPER_ADMIN, 503); abort_if($request->user()->permission < User::SUPER_ADMIN, 503);
return $next($request); return $next($request);
} }
} }

View File

@ -26,6 +26,7 @@ trait HasPassword
public function getEncryptedPwdFromEvent($raw) public function getEncryptedPwdFromEvent($raw)
{ {
$responses = event(new EncryptUserPassword($raw, $this)); $responses = event(new EncryptUserPassword($raw, $this));
return Arr::get($responses, 0); return Arr::get($responses, 0);
} }
@ -39,6 +40,7 @@ trait HasPassword
{ {
$responses = event(new EncryptUserPassword($password, $this)); $responses = event(new EncryptUserPassword($password, $this));
$this->password = Arr::get($responses, 0, app('cipher')->hash($password, config('secure.salt'))); $this->password = Arr::get($responses, 0, app('cipher')->hash($password, config('secure.salt')));
return $this->save(); return $this->save();
} }
} }

View File

@ -65,6 +65,7 @@ class User extends Authenticatable implements JWTSubject
if (Arr::has(static::$mappings, $item['column'])) { if (Arr::has(static::$mappings, $item['column'])) {
$item['column'] = static::$mappings[$item['column']]; $item['column'] = static::$mappings[$item['column']];
} }
return $item; return $item;
}; };
$mapColumn = function ($column) { $mapColumn = function ($column) {
@ -86,6 +87,7 @@ class User extends Authenticatable implements JWTSubject
} }
$builder->setQuery($query); $builder->setQuery($query);
return $builder; return $builder;
}); });
} }

View File

@ -2,10 +2,6 @@
namespace App\Providers; namespace App\Providers;
use Event;
use App\Events;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use App\Services\PluginManager; use App\Services\PluginManager;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;

View File

@ -2,8 +2,6 @@
namespace App\Services; namespace App\Services;
use Storage;
use Exception;
use App\Events; use App\Events;
use Composer\Semver\Semver; use Composer\Semver\Semver;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
@ -118,6 +116,7 @@ class PluginManager
}); });
$this->plugins = $plugins; $this->plugins = $plugins;
return $plugins; return $plugins;
} }
@ -313,11 +312,13 @@ class PluginManager
->mapWithKeys(function ($constraint, $name) { ->mapWithKeys(function ($constraint, $name) {
if ($name == 'blessing-skin-server') { if ($name == 'blessing-skin-server') {
$version = config('app.version'); $version = config('app.version');
return (! Semver::satisfies($version, $constraint)) return (! Semver::satisfies($version, $constraint))
? [$name => compact('version', 'constraint')] ? [$name => compact('version', 'constraint')]
: []; : [];
} elseif ($name == 'php') { } elseif ($name == 'php') {
$version = PHP_VERSION; $version = PHP_VERSION;
return (! Semver::satisfies($version, $constraint)) return (! Semver::satisfies($version, $constraint))
? [$name => compact('version', 'constraint')] ? [$name => compact('version', 'constraint')]
: []; : [];
@ -325,6 +326,7 @@ class PluginManager
return [$name => ['version' => null, 'constraint' => $constraint]]; return [$name => ['version' => null, 'constraint' => $constraint]];
} else { } else {
$version = $this->enabled->get($name)['version']; $version = $this->enabled->get($name)['version'];
return (! Semver::satisfies($version, $constraint)) return (! Semver::satisfies($version, $constraint))
? [$name => compact('version', 'constraint')] ? [$name => compact('version', 'constraint')]
: []; : [];

View File

@ -3,7 +3,6 @@
declare(strict_types=1); declare(strict_types=1);
use Carbon\Carbon; use Carbon\Carbon;
use App\Models\User;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -13,8 +12,9 @@ if (! function_exists('webpack_assets')) {
if (env('WEBPACK_ENV', 'production') == 'development') { if (env('WEBPACK_ENV', 'production') == 'development') {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$host = parse_url(url('/'), PHP_URL_HOST); $host = parse_url(url('/'), PHP_URL_HOST);
return "http://$host:8080/$relativeUri"; return "http://$host:8080/$relativeUri";
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} else { } else {
$path = app('webpack')->$relativeUri; $path = app('webpack')->$relativeUri;
$cdn = option('cdn_address'); $cdn = option('cdn_address');
@ -125,7 +125,7 @@ if (! function_exists('bs_menu')) {
$menu[$type] = array_map(function ($item) { $menu[$type] = array_map(function ($item) {
if (Arr::get($item, 'id') === 'plugin-configs') { if (Arr::get($item, 'id') === 'plugin-configs') {
$pluginConfigs = app('plugins')->getEnabledPlugins() $pluginConfigs = app('plugins')->getEnabledPlugins()
->filter(function ($plugin) { ->filter(function ($plugin) {
return $plugin->hasConfigView(); return $plugin->hasConfigView();
}) })

View File

@ -4,7 +4,6 @@ namespace Tests;
use Cache; use Cache;
use Redis; use Redis;
use App\Models\User;
use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;

View File

@ -4,8 +4,8 @@ namespace Tests;
use Notification; use Notification;
use App\Models\User; use App\Models\User;
use App\Notifications;
use App\Models\Player; use App\Models\Player;
use App\Notifications;
use App\Models\Texture; use App\Models\Texture;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\WithoutMiddleware;
@ -53,6 +53,7 @@ class AdminControllerTest extends TestCase
Notifications\SiteMessage::class, Notifications\SiteMessage::class,
function ($notification) { function ($notification) {
$this->assertEquals('all users', $notification->title); $this->assertEquals('all users', $notification->title);
return true; return true;
} }
); );
@ -70,6 +71,7 @@ class AdminControllerTest extends TestCase
function ($notification) { function ($notification) {
$this->assertEquals('normal only', $notification->title); $this->assertEquals('normal only', $notification->title);
$this->assertEquals('hi', $notification->content); $this->assertEquals('hi', $notification->content);
return true; return true;
} }
); );
@ -88,6 +90,7 @@ class AdminControllerTest extends TestCase
Notifications\SiteMessage::class, Notifications\SiteMessage::class,
function ($notification) { function ($notification) {
$this->assertEquals('uid', $notification->title); $this->assertEquals('uid', $notification->title);
return true; return true;
} }
); );
@ -106,6 +109,7 @@ class AdminControllerTest extends TestCase
Notifications\SiteMessage::class, Notifications\SiteMessage::class,
function ($notification) { function ($notification) {
$this->assertEquals('email', $notification->title); $this->assertEquals('email', $notification->title);
return true; return true;
} }
); );

View File

@ -3,7 +3,6 @@
namespace Tests; namespace Tests;
use Schema; use Schema;
use Artisan;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;

View File

@ -92,6 +92,7 @@ class PluginControllerTest extends TestCase
$mock->shouldReceive('getUnsatisfied') $mock->shouldReceive('getUnsatisfied')
->withArgs(function ($plugin) { ->withArgs(function ($plugin) {
$this->assertEquals('fake2', $plugin->name); $this->assertEquals('fake2', $plugin->name);
return true; return true;
}) })
->once() ->once()
@ -110,6 +111,7 @@ class PluginControllerTest extends TestCase
$mock->shouldReceive('getUnsatisfied') $mock->shouldReceive('getUnsatisfied')
->withArgs(function ($plugin) { ->withArgs(function ($plugin) {
$this->assertEquals('fake3', $plugin->name); $this->assertEquals('fake3', $plugin->name);
return true; return true;
}) })
->once() ->once()
@ -208,11 +210,12 @@ class PluginControllerTest extends TestCase
->andReturn(collect([new Plugin('', [ ->andReturn(collect([new Plugin('', [
'name' => 'a', 'name' => 'a',
'version' => '0.0.0', 'version' => '0.0.0',
'title' => '' 'title' => '',
])])); ])]));
$mock->shouldReceive('getUnsatisfied') $mock->shouldReceive('getUnsatisfied')
->withArgs(function ($plugin) { ->withArgs(function ($plugin) {
$this->assertEquals('a', $plugin->name); $this->assertEquals('a', $plugin->name);
return true; return true;
}) })
->once() ->once()

View File

@ -11,6 +11,7 @@ class FilterTest extends TestCase
->withArgs(function ($hook, $callback) { ->withArgs(function ($hook, $callback) {
$this->assertEquals('my.hook', $hook); $this->assertEquals('my.hook', $hook);
$this->assertEquals('Filtered text', $callback('text')); $this->assertEquals('Filtered text', $callback('text'));
return true; return true;
}) })
->once(); ->once();

View File

@ -101,6 +101,7 @@ class HookTest extends TestCase
{ {
$response = $next($request); $response = $next($request);
$response->header('X-Middleware-Test', 'value'); $response->header('X-Middleware-Test', 'value');
return $response; return $response;
} }
})); }));

View File

@ -19,6 +19,7 @@ class PluginManagerTest extends TestCase
$property->setValue($manager, false); $property->setValue($manager, false);
$manager->boot(); $manager->boot();
return $manager; return $manager;
} }
@ -148,6 +149,7 @@ class PluginManagerTest extends TestCase
$manager = $this->rebootPluginManager(app('plugins')); $manager = $this->rebootPluginManager(app('plugins'));
Event::assertDispatched(\App\Events\PluginVersionChanged::class, function ($event) { Event::assertDispatched(\App\Events\PluginVersionChanged::class, function ($event) {
$this->assertEquals('0.1.0', $event->plugin->version); $this->assertEquals('0.1.0', $event->plugin->version);
return true; return true;
}); });
@ -390,6 +392,7 @@ class PluginManagerTest extends TestCase
$manager->enable('fake'); $manager->enable('fake');
Event::assertDispatched(Events\PluginWasEnabled::class, function ($event) { Event::assertDispatched(Events\PluginWasEnabled::class, function ($event) {
$this->assertEquals('fake', $event->plugin->name); $this->assertEquals('fake', $event->plugin->name);
return true; return true;
}); });
$this->assertTrue($manager->getEnabledPlugins()->has('fake')); $this->assertTrue($manager->getEnabledPlugins()->has('fake'));
@ -414,6 +417,7 @@ class PluginManagerTest extends TestCase
$manager->disable('fake'); $manager->disable('fake');
Event::assertDispatched(Events\PluginWasDisabled::class, function ($event) { Event::assertDispatched(Events\PluginWasDisabled::class, function ($event) {
$this->assertEquals('fake', $event->plugin->name); $this->assertEquals('fake', $event->plugin->name);
return true; return true;
}); });
$this->assertFalse($manager->getEnabledPlugins()->has('fake')); $this->assertFalse($manager->getEnabledPlugins()->has('fake'));
@ -439,10 +443,12 @@ class PluginManagerTest extends TestCase
$manager->delete('fake'); $manager->delete('fake');
Event::assertDispatched(Events\PluginWasDisabled::class, function ($event) { Event::assertDispatched(Events\PluginWasDisabled::class, function ($event) {
$this->assertEquals('fake', $event->plugin->name); $this->assertEquals('fake', $event->plugin->name);
return true; return true;
}); });
Event::assertDispatched(Events\PluginWasDeleted::class, function ($event) { Event::assertDispatched(Events\PluginWasDeleted::class, function ($event) {
$this->assertEquals('fake', $event->plugin->name); $this->assertEquals('fake', $event->plugin->name);
return true; return true;
}); });
$this->assertFalse($manager->getEnabledPlugins()->has('fake')); $this->assertFalse($manager->getEnabledPlugins()->has('fake'));

View File

@ -3,7 +3,6 @@
namespace Tests; namespace Tests;
use File; use File;
use App\Services\Webpack;
class WebpackTest extends TestCase class WebpackTest extends TestCase
{ {

View File

@ -2,7 +2,6 @@
namespace Tests; namespace Tests;
use DB;
use Mockery; use Mockery;
use Exception; use Exception;
use CreateAllTables; use CreateAllTables;
@ -180,8 +179,8 @@ class SetupControllerTest extends TestCase
'--force' => true, '--force' => true,
'--path' => [ '--path' => [
'database/migrations', 'database/migrations',
'vendor/laravel/passport/database/migrations' 'vendor/laravel/passport/database/migrations',
] ],
]) ])
->once() ->once()
->andReturnUsing(function () { ->andReturnUsing(function () {