Skip to content

Commit

Permalink
Code Format
Browse files Browse the repository at this point in the history
  • Loading branch information
hasinhayder committed Jan 7, 2024
1 parent f9c7bbe commit 677d991
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 52 deletions.
1 change: 0 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Kernel extends ConsoleKernel {
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule) {
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function index() {
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
Expand All @@ -44,7 +43,6 @@ public function store(Request $request) {
/**
* Display the specified resource.
*
* @param \App\Models\Role $role
* @return \App\Models\Role $role
*/
public function show(Role $role) {
Expand All @@ -54,11 +52,9 @@ public function show(Role $role) {
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Role $role
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|Role
*/
public function update(Request $request, Role $role = null) {
public function update(Request $request, ?Role $role = null) {
if (! $role) {
return response(['error' => 1, 'message' => 'role doesn\'t exist'], 404);
}
Expand All @@ -80,7 +76,6 @@ public function update(Request $request, Role $role = null) {
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Role $role
* @return \Illuminate\Http\Response
*/
public function destroy(Role $role) {
Expand Down
11 changes: 2 additions & 9 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function index() {
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
Expand Down Expand Up @@ -51,7 +50,6 @@ public function store(Request $request) {
/**
* Authenticate an user and dispatch token.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function login(Request $request) {
Expand All @@ -73,13 +71,12 @@ public function login(Request $request) {

$plainTextToken = $user->createToken('hydra-api-token', $roles)->plainTextToken;

return response(['error' => 0, 'id' => $user->id, 'token' => $plainTextToken], 200);
return response(['error' => 0, 'id' => $user->id, 'name' => $user->name, 'token' => $plainTextToken], 200);
}

/**
* Display the specified resource.
*
* @param \App\Models\User $user
* @return \App\Models\User $user
*/
public function show(User $user) {
Expand All @@ -89,8 +86,6 @@ public function show(User $user) {
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\User $user
* @return User
*
* @throws MissingAbilityException
Expand Down Expand Up @@ -118,7 +113,6 @@ public function update(Request $request, User $user) {
/**
* Remove the specified resource from storage.
*
* @param \App\Models\User $user
* @return \Illuminate\Http\Response
*/
public function destroy(User $user) {
Expand All @@ -128,7 +122,7 @@ public function destroy(User $user) {
if ($userRoles->contains($adminRole)) {
//the current user is admin, then if there is only one admin - don't delete
$numberOfAdmins = Role::where('slug', 'admin')->first()->users()->count();
if (1 == $numberOfAdmins) {
if ($numberOfAdmins == 1) {
return response(['error' => 1, 'message' => 'Create another admin before deleting this only admin user'], 409);
}
}
Expand All @@ -141,7 +135,6 @@ public function destroy(User $user) {
/**
* Return Auth user
*
* @param Request $request
* @return mixed
*/
public function me(Request $request) {
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/UserRoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class UserRoleController extends Controller {
/**
* Display a listing of the resource.
*
* @param \App\Models\User $user
* @return \App\Models\User $user
*/
public function index(User $user) {
Expand All @@ -20,8 +19,6 @@ public function index(User $user) {
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\User $user
* @return \App\Models\User $user
*/
public function store(Request $request, User $user) {
Expand All @@ -39,8 +36,6 @@ public function store(Request $request, User $user) {
/**
* Remove the specified resource from storage.
*
* @param \App\Models\User $user
* @param \App\Models\Role $role
* @return \App\Models\User $user
*/
public function destroy(User $user, Role $role) {
Expand Down
1 change: 0 additions & 1 deletion app/Http/Middleware/HydraLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class HydraLog {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
Expand Down
1 change: 0 additions & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class RedirectIfAuthenticated {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
public function up() {
Schema::table('personal_access_tokens', function (Blueprint $table) {
$table->timestamp('expires_at')->nullable()->after('last_used_at');
});
Expand All @@ -23,8 +21,7 @@ public function up()
*
* @return void
*/
public function down()
{
public function down() {
Schema::table('personal_access_token', function (Blueprint $table) {
$table->dropColumn('expires_at');
});
Expand Down
16 changes: 8 additions & 8 deletions tests/Feature/AdminLoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public function test_admin_login() {
]);

$response
->assertJson(fn (AssertableJson $json) => $json->where('error', 0)
->has('token')
->etc()
);
->assertJson(fn (AssertableJson $json) => $json->where('error', 0)
->has('token')
->etc()
);
}

public function test_admin_login_fail() {
Expand All @@ -31,9 +31,9 @@ public function test_admin_login_fail() {
]);

$response
->assertJson(fn (AssertableJson $json) => $json->where('error', 1)
->missing('token')
->has('message')
);
->assertJson(fn (AssertableJson $json) => $json->where('error', 1)
->missing('token')
->has('message')
);
}
}
30 changes: 15 additions & 15 deletions tests/Feature/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function test_update_role_name_as_admin() {
$response
->assertJson(
fn (AssertableJson $json) => $json->where('name', 'Chief Editor')
->missing('error')
->etc()
->missing('error')
->etc()
);
}

Expand All @@ -78,8 +78,8 @@ public function test_update_role_slug_as_admin() {
$response
->assertJson(
fn (AssertableJson $json) => $json->where('slug', 'chief-editor')
->missing('error')
->etc()
->missing('error')
->etc()
);
}

Expand All @@ -102,9 +102,9 @@ public function test_update_role_namd_and_slug_as_admin() {
$response
->assertJson(
fn (AssertableJson $json) => $json->where('name', 'Editor X')
->where('slug', 'editor-x')
->missing('error')
->etc()
->where('slug', 'editor-x')
->missing('error')
->etc()
);
}

Expand All @@ -126,8 +126,8 @@ public function test_update_admin_slug_as_admin_should_fail() {
$response
->assertJson(
fn (AssertableJson $json) => $json
->where('slug', 'admin')
->etc()
->where('slug', 'admin')
->etc()
);
}

Expand All @@ -150,9 +150,9 @@ public function test_create_new_role_as_admin() {
$response
->assertJson(
fn (AssertableJson $json) => $json->where('name', 'New Role')
->where('slug', 'new-role')
->missing('error')
->etc()
->where('slug', 'new-role')
->missing('error')
->etc()
);
}

Expand All @@ -175,7 +175,7 @@ public function test_duplicate_role_will_not_be_created() {
$response
->assertJson(
fn (AssertableJson $json) => $json->where('error', 1)
->etc()
->etc()
);
}

Expand All @@ -197,7 +197,7 @@ public function test_delete_role_as_admin() {
$response
->assertJson(
fn (AssertableJson $json) => $json->where('error', 0)
->has('message')
->has('message')
);
}

Expand All @@ -219,7 +219,7 @@ public function test_delete_admin_role_should_fail() {
$response
->assertJson(
fn (AssertableJson $json) => $json->where('error', 1)
->has('message')
->has('message')
);
}
}

0 comments on commit 677d991

Please sign in to comment.