Skip to content

Commit 4da7922

Browse files
committed
Code cleanup to use new findCountWhere function
1 parent c1a078b commit 4da7922

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

app/Services/Servers/DeletionService.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,11 @@ public function handle($server)
141141
}
142142

143143
$this->database->beginTransaction();
144-
145144
$this->databaseRepository->withColumns('id')->findWhere([['server_id', '=', $server->id]])->each(function ($item) {
146145
$this->databaseManagementService->delete($item->id);
147146
});
148147

149148
$this->repository->delete($server->id);
150-
151149
$this->database->commit();
152150
}
153151
}

app/Services/Users/DeletionService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public function handle($user)
7878
$user = $user->id;
7979
}
8080

81-
$servers = $this->serverRepository->findWhere([['owner_id', '=', $user]]);
82-
if (count($servers) > 0) {
81+
$servers = $this->serverRepository->withColumns('id')->findCountWhere([['owner_id', '=', $user]]);
82+
if ($servers > 0) {
8383
throw new DisplayException($this->translator->trans('admin/user.exceptions.user_has_servers'));
8484
}
8585

app/Services/Users/UpdateService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public function handle($id, array $data)
6868
$data['password'] = $this->hasher->make($data['password']);
6969
}
7070

71-
$user = $this->repository->update($id, $data);
72-
73-
return $user;
71+
return $this->repository->update($id, $data);
7472
}
7573
}

tests/Unit/Services/Users/DeletionServiceTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public function setUp()
8181
*/
8282
public function testUserIsDeletedIfNoServersAreAttachedToAccount()
8383
{
84-
$this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn([]);
84+
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
85+
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
8586
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
8687

8788
$this->assertTrue(
@@ -97,7 +98,8 @@ public function testUserIsDeletedIfNoServersAreAttachedToAccount()
9798
*/
9899
public function testExceptionIsThrownIfServersAreAttachedToAccount()
99100
{
100-
$this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(['item']);
101+
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
102+
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(1);
101103
$this->translator->shouldReceive('trans')->with('admin/user.exceptions.user_has_servers')->once()->andReturnNull();
102104

103105
$this->service->handle($this->user->id);
@@ -108,7 +110,8 @@ public function testExceptionIsThrownIfServersAreAttachedToAccount()
108110
*/
109111
public function testModelCanBePassedInPlaceOfUserId()
110112
{
111-
$this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn([]);
113+
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
114+
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
112115
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
113116

114117
$this->assertTrue(

0 commit comments

Comments
 (0)