diff --git a/src/LaravelRestifyServiceProvider.php b/src/LaravelRestifyServiceProvider.php index 88c8d3df3..c9a3681ec 100644 --- a/src/LaravelRestifyServiceProvider.php +++ b/src/LaravelRestifyServiceProvider.php @@ -84,7 +84,7 @@ protected function registerPublishing() $migrationFileName = 'create_action_logs_table.php'; if (! $this->migrationFileExists($migrationFileName)) { $this->publishes([ - __DIR__ . "/../database/migrations/{$migrationFileName}" => database_path('migrations/' . date('Y_m_d_His', time()) . '_' . $migrationFileName), + __DIR__."/../database/migrations/{$migrationFileName}" => database_path('migrations/'.date('Y_m_d_His', time()).'_'.$migrationFileName), ], 'restify-migrations'); } @@ -98,7 +98,7 @@ protected function registerPublishing() public static function migrationFileExists(string $migrationFileName): bool { $len = strlen($migrationFileName); - foreach (glob(database_path("migrations/*.php")) as $filename) { + foreach (glob(database_path('migrations/*.php')) as $filename) { if ((substr($filename, -$len) === $migrationFileName)) { return true; } diff --git a/src/Models/ActionLog.php b/src/Models/ActionLog.php index 944b2f5fe..51079c646 100644 --- a/src/Models/ActionLog.php +++ b/src/Models/ActionLog.php @@ -7,7 +7,7 @@ use Illuminate\Support\Str; /** - * Class ActionLog + * Class ActionLog. * @property string batch_id * @property string user_id * @property string name @@ -22,7 +22,6 @@ * @property string original * @property string changes * @property string exception - * @package Binaryk\LaravelRestify\Models */ class ActionLog extends Model { @@ -44,7 +43,7 @@ class ActionLog extends Model public static function forRepositoryStored(Model $model, Authenticatable $user = null, array $dirty = null): self { return new static([ - 'batch_id' => (string)Str::uuid(), + 'batch_id' => (string) Str::uuid(), 'user_id' => optional($user)->getAuthIdentifier(), 'name' => static::ACTION_CREATED, 'actionable_type' => $model->getMorphClass(), @@ -66,7 +65,7 @@ public static function forRepositoryStored(Model $model, Authenticatable $user = public static function forRepositoryUpdated(Model $model, Authenticatable $user = null): self { return new static([ - 'batch_id' => (string)Str::uuid(), + 'batch_id' => (string) Str::uuid(), 'user_id' => optional($user)->getAuthIdentifier(), 'name' => static::ACTION_UPDATED, 'actionable_type' => $model->getMorphClass(), @@ -88,7 +87,7 @@ public static function forRepositoryUpdated(Model $model, Authenticatable $user public static function forRepositoryDestroy(Model $model, Authenticatable $user = null): self { return new static([ - 'batch_id' => (string)Str::uuid(), + 'batch_id' => (string) Str::uuid(), 'user_id' => optional($user)->getAuthIdentifier(), 'name' => static::ACTION_DELETED, 'actionable_type' => $model->getMorphClass(), diff --git a/src/Repositories/ActionLogRepository.php b/src/Repositories/ActionLogRepository.php index d4def683d..36cd295a9 100644 --- a/src/Repositories/ActionLogRepository.php +++ b/src/Repositories/ActionLogRepository.php @@ -14,7 +14,7 @@ public function fields(RestifyRequest $request) return [ field('actionable_type'), - field('actionable_id') + field('actionable_id'), ]; } } diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index c84d00612..4c2a6c82a 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -842,7 +842,6 @@ public function detach(RestifyRequest $request, $repositoryId, Collection $pivot public function destroy(RestifyRequest $request, $repositoryId) { $status = DB::transaction(function () use ($request) { - if ($this->resource instanceof ActionLogable) { Restify::actionLog() ->forRepositoryDestroy($this->resource, $request->user()) diff --git a/src/Services/Concerns/ResetsPasswords.php b/src/Services/Concerns/ResetsPasswords.php index dac2f167f..6aa8166c8 100644 --- a/src/Services/Concerns/ResetsPasswords.php +++ b/src/Services/Concerns/ResetsPasswords.php @@ -148,7 +148,7 @@ protected function sendResetResponse($response) protected function sendResetFailedResponse(Request $request, $response) { return response()->json(['email' => [ - trans($response) + trans($response), ]])->setStatusCode(400); } diff --git a/src/Services/ForgotPasswordService.php b/src/Services/ForgotPasswordService.php index 328546079..ffa0ee65b 100644 --- a/src/Services/ForgotPasswordService.php +++ b/src/Services/ForgotPasswordService.php @@ -72,9 +72,9 @@ protected function sendResetLinkFailedResponse(Request $request, $response) return response()->json([ 'errors' => [ 'email' => [ - trans($response) - ] - ] + trans($response), + ], + ], ])->setStatusCode(400); } } diff --git a/tests/Controllers/RepositoryUpdateControllerTest.php b/tests/Controllers/RepositoryUpdateControllerTest.php index 95f4a1f44..4de518a95 100644 --- a/tests/Controllers/RepositoryUpdateControllerTest.php +++ b/tests/Controllers/RepositoryUpdateControllerTest.php @@ -23,7 +23,7 @@ public function test_basic_update_works() { $post = factory(Post::class)->create(); - $this->patch('posts/' . $post->id, [ + $this->patch('posts/'.$post->id, [ 'title' => 'Updated title', ])->assertStatus(200); @@ -34,7 +34,7 @@ public function test_put_works() { $post = factory(Post::class)->create(); - $this->withoutExceptionHandling()->put('posts/' . $post->id, [ + $this->withoutExceptionHandling()->put('posts/'.$post->id, [ 'title' => 'Updated title', ])->assertStatus(200); @@ -51,7 +51,7 @@ public function test_unathorized_to_update() $_SERVER['restify.post.update'] = false; - $this->patch('posts/' . $post->id, [ + $this->patch('posts/'.$post->id, [ 'title' => 'Updated title', ])->assertStatus(403) ->assertJson([ @@ -65,7 +65,7 @@ public function test_do_not_update_fields_without_permission() $_SERVER['posts.authorizable.title'] = false; - $response = $this->putJson('post-with-unathorized-fields/' . $post->id, [ + $response = $this->putJson('post-with-unathorized-fields/'.$post->id, [ 'title' => 'Updated title', 'user_id' => 2, ]) @@ -81,7 +81,7 @@ public function test_will_not_update_readonly_fields() $post = factory(Post::class)->create(['image' => null]); - $r = $this->putJson('posts-unauthorized-fields/' . $post->id, [ + $r = $this->putJson('posts-unauthorized-fields/'.$post->id, [ 'user_id' => $user->id, 'image' => 'avatar.png', 'title' => 'Some post title', @@ -108,7 +108,7 @@ public function test_updating_repository_log_action() 'user_id' => $this->authenticatedAs->getAuthIdentifier(), 'name' => ActionLog::ACTION_UPDATED, 'actionable_type' => Post::class, - 'actionable_id' => (string)$post->id + 'actionable_id' => (string) $post->id, ]); $log = ActionLog::latest()->first(); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 6ff283a66..d8184aac3 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -52,7 +52,7 @@ protected function setUp(): void $this->repositoryMock(); $this->loadMigrations(); $this->loadRoutes(); - $this->withFactories(__DIR__ . '/Factories'); + $this->withFactories(__DIR__.'/Factories'); $this->injectTranslator(); $this->app->bind(ExceptionHandler::class, RestifyHandler::class); @@ -87,7 +87,7 @@ protected function getEnvironmentSetUp($app) 'prefix' => '', ]); - include_once __DIR__ . '/../database/migrations/create_action_logs_table.php'; + include_once __DIR__.'/../database/migrations/create_action_logs_table.php'; (new \CreateActionLogsTable())->up(); } @@ -100,7 +100,7 @@ protected function loadMigrations() { $this->loadMigrationsFrom([ '--database' => 'sqlite', - '--path' => realpath(__DIR__ . DIRECTORY_SEPARATOR . 'Migrations'), + '--path' => realpath(__DIR__.DIRECTORY_SEPARATOR.'Migrations'), ]); } @@ -237,7 +237,7 @@ public function mockUsers($count = 1, $predefinedEmails = []) $i = 0; while ($i < $count) { $users->push(factory(User::class)->create()); - $i ++; + $i++; } foreach ($predefinedEmails as $email) { @@ -262,7 +262,7 @@ public function mockPosts($userId, $count = 1) $users->push(factory(Post::class)->create( ['user_id' => $userId] )); - $i ++; + $i++; } return $users->shuffle(); // randomly shuffles the items in the collection @@ -270,23 +270,21 @@ public function mockPosts($userId, $count = 1) public function getTempDirectory($suffix = ''): string { - return __DIR__ . '/TestSupport/temp' . ($suffix == '' ? '' : '/' . $suffix); + return __DIR__.'/TestSupport/temp'.($suffix == '' ? '' : '/'.$suffix); } public function getMediaDirectory($suffix = ''): string { - return $this->getTempDirectory() . '/media' . ($suffix == '' ? '' : '/' . $suffix); + return $this->getTempDirectory().'/media'.($suffix == '' ? '' : '/'.$suffix); } public function getTestFilesDirectory($suffix = ''): string { - return $this->getTempDirectory() . '/testfiles' . ($suffix == '' ? '' : '/' . $suffix); + return $this->getTempDirectory().'/testfiles'.($suffix == '' ? '' : '/'.$suffix); } public function getTestJpg(): string { return $this->getTestFilesDirectory('test.jpg'); } - - }