Skip to content

Commit

Permalink
refactor: rename *WithTransaction methods to run*Operation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzarbn committed Oct 20, 2023
1 parent e7e6040 commit cd2e6fd
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 56 deletions.
30 changes: 12 additions & 18 deletions src/Concerns/HandlesRelationManyToManyOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function attach(Request $request, int|string $parentKey): JsonResponse|Re
{
try {
$this->startTransaction();
$result = $this->attachWithTransaction($request, $parentKey);
$result = $this->runAttachOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -45,7 +45,7 @@ public function attach(Request $request, int|string $parentKey): JsonResponse|Re
* @return JsonResponse|Response
* @throws BindingResolutionException
*/
protected function attachWithTransaction(Request $request, int|string $parentKey): JsonResponse|Response
protected function runAttachOperation(Request $request, int|string $parentKey): JsonResponse|Response
{
$parentQuery = $this->buildAttachParentFetchQuery($request, $parentKey);
$parentEntity = $this->runAttachParentFetchQuery($request, $parentQuery, $parentKey);
Expand All @@ -69,11 +69,7 @@ protected function attachWithTransaction(Request $request, int|string $parentKey
return $afterHookResult;
}

return response()->json(
[
'attached' => Arr::get($attachResult, 'attached', []),
]
);
return response()->json(['attached' => Arr::get($attachResult, 'attached', [])]);
}

/**
Expand Down Expand Up @@ -169,9 +165,7 @@ protected function preparePivotFields(array $pivotFields): array
}
}

$pivotFields = Arr::only($pivotFields, $this->getPivotFillable());

return $pivotFields;
return Arr::only($pivotFields, $this->getPivotFillable());
}

/**
Expand Down Expand Up @@ -278,7 +272,7 @@ public function detach(Request $request, int|string $parentKey): JsonResponse|Re
{
try {
$this->startTransaction();
$result = $this->detachWithTransaction($request, $parentKey);
$result = $this->runDetachOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -294,7 +288,7 @@ public function detach(Request $request, int|string $parentKey): JsonResponse|Re
* @return JsonResponse|Response
* @throws BindingResolutionException
*/
protected function detachWithTransaction(Request $request, int|string $parentKey): JsonResponse|Response
protected function runDetachOperation(Request $request, int|string $parentKey): JsonResponse|Response
{
$parentQuery = $this->buildDetachParentFetchQuery($request, $parentKey);
$parentEntity = $this->runDetachParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -404,7 +398,7 @@ public function sync(Request $request, int|string $parentKey): JsonResponse|Resp
{
try {
$this->startTransaction();
$result = $this->syncWithTransaction($request, $parentKey);
$result = $this->runSyncOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -420,7 +414,7 @@ public function sync(Request $request, int|string $parentKey): JsonResponse|Resp
* @return JsonResponse|Response
* @throws BindingResolutionException
*/
protected function syncWithTransaction(Request $request, int|string $parentKey): JsonResponse|Response
protected function runSyncOperation(Request $request, int|string $parentKey): JsonResponse|Response
{
$parentQuery = $this->buildSyncParentFetchQuery($request, $parentKey);
$parentEntity = $this->runSyncParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -533,7 +527,7 @@ public function toggle(Request $request, int|string $parentKey): JsonResponse|Re
{
try {
$this->startTransaction();
$result = $this->toggleWithTransaction($request, $parentKey);
$result = $this->runToggleOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -549,7 +543,7 @@ public function toggle(Request $request, int|string $parentKey): JsonResponse|Re
* @return JsonResponse|Response
* @throws BindingResolutionException
*/
protected function toggleWithTransaction(Request $request, int|string $parentKey): JsonResponse|Response
protected function runToggleOperation(Request $request, int|string $parentKey): JsonResponse|Response
{
$parentQuery = $this->buildToggleParentFetchQuery($request, $parentKey);
$parentEntity = $this->runToggleParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -654,7 +648,7 @@ public function updatePivot(Request $request, int|string $parentKey, int|string
{
try {
$this->startTransaction();
$result = $this->updatePivotWithTransaction($request, $parentKey, $relatedKey);
$result = $this->runUpdatePivotOperation($request, $parentKey, $relatedKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -671,7 +665,7 @@ public function updatePivot(Request $request, int|string $parentKey, int|string
* @return JsonResponse|Response
* @throws BindingResolutionException
*/
protected function updatePivotWithTransaction(
protected function runUpdatePivotOperation(
Request $request,
int|string $parentKey,
int|string $relatedKey
Expand Down
8 changes: 4 additions & 4 deletions src/Concerns/HandlesRelationOneToManyOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function associate(Request $request, int|string $parentKey): Resource|Res
{
try {
$this->startTransaction();
$result = $this->associateWithTransaction($request, $parentKey);
$result = $this->runAssociateOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -43,7 +43,7 @@ public function associate(Request $request, int|string $parentKey): Resource|Res
* @return Resource|Response
* @throws BindingResolutionException
*/
protected function associateWithTransaction(Request $request, int|string $parentKey): Resource|Response
protected function runAssociateOperation(Request $request, int|string $parentKey): Resource|Response
{
$parentQuery = $this->buildAssociateParentFetchQuery($request, $parentKey);
$parentEntity = $this->runAssociateParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -181,7 +181,7 @@ public function dissociate(Request $request, int|string $parentKey, int|string|n
{
try {
$this->startTransaction();
$result = $this->dissociateWithTransaction($request, $parentKey, $relatedKey);
$result = $this->runDissociateOperation($request, $parentKey, $relatedKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -198,7 +198,7 @@ public function dissociate(Request $request, int|string $parentKey, int|string|n
* @return Resource|Response
* @throws BindingResolutionException
*/
protected function dissociateWithTransaction(Request $request, int|string $parentKey, int|string|null $relatedKey): Resource|Response
protected function runDissociateOperation(Request $request, int|string $parentKey, int|string|null $relatedKey): Resource|Response
{
$parentQuery = $this->buildDissociateParentFetchQuery($request, $parentKey);
$parentEntity = $this->runDissociateParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down
18 changes: 9 additions & 9 deletions src/Concerns/HandlesRelationStandardBatchOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function batchStore(Request $request, int|string $parentKey): CollectionR
{
try {
$this->startTransaction();
$result = $this->batchStoreWithTransaction($request, $parentKey);
$result = $this->runBatchStoreOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -46,7 +46,7 @@ public function batchStore(Request $request, int|string $parentKey): CollectionR
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws BindingResolutionException
*/
protected function batchStoreWithTransaction(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchStoreOperation(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
{
$parentQuery = $this->buildBatchStoreParentFetchQuery($request, $parentKey);
$parentEntity = $this->runBatchStoreParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -176,14 +176,14 @@ protected function afterBatchStore(Request $request, Model $parentEntity, Collec
*
* @param Request $request
* @param int|string $parentKey
* @return CollectionResCollectionResource|AnonymousResourceCollection|Responseource
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws Exception
*/
public function batchUpdate(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
{
try {
$this->startTransaction();
$result = $this->batchUpdateWithTransaction($request, $parentKey);
$result = $this->runBatchUpdateOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -199,7 +199,7 @@ public function batchUpdate(Request $request, int|string $parentKey): Collection
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws BindingResolutionException
*/
protected function batchUpdateWithTransaction(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchUpdateOperation(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
{
$parentQuery = $this->buildBatchUpdateParentFetchQuery($request, $parentKey);
$parentEntity = $this->runBatchUpdateParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -386,7 +386,7 @@ public function batchDestroy(Request $request, int|string $parentKey): Collectio
{
try {
$this->startTransaction();
$result = $this->batchDestroyWithTransaction($request, $parentKey);
$result = $this->runBatchDestroyOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -402,7 +402,7 @@ public function batchDestroy(Request $request, int|string $parentKey): Collectio
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws Exception
*/
protected function batchDestroyWithTransaction(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchDestroyOperation(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
{
$parentQuery = $this->buildBatchDestroyParentFetchQuery($request, $parentKey);
$parentEntity = $this->runBatchDestroyParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -559,7 +559,7 @@ public function batchRestore(Request $request, int|string $parentKey): Collectio
{
try {
$this->startTransaction();
$result = $this->batchRestoreWithTransaction($request, $parentKey);
$result = $this->runBatchRestoreOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -575,7 +575,7 @@ public function batchRestore(Request $request, int|string $parentKey): Collectio
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws Exception
*/
protected function batchRestoreWithTransaction(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchRestoreOperation(Request $request, int|string $parentKey): CollectionResource|AnonymousResourceCollection|Response
{
$parentQuery = $this->buildBatchRestoreParentFetchQuery($request, $parentKey);
$parentEntity = $this->runBatchRestoreParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down
16 changes: 8 additions & 8 deletions src/Concerns/HandlesRelationStandardOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function store(Request $request, int|string $parentKey): Resource|Respons
{
try {
$this->startTransaction();
$result = $this->storeWithTransaction($request, $parentKey);
$result = $this->runStoreOperation($request, $parentKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -286,7 +286,7 @@ public function store(Request $request, int|string $parentKey): Resource|Respons
* @return Resource|Response
* @throws BindingResolutionException
*/
protected function storeWithTransaction(Request $request, string|int $parentKey): Resource|Response
protected function runStoreOperation(Request $request, string|int $parentKey): Resource|Response
{
$parentQuery = $this->buildStoreParentFetchQuery($request, $parentKey);
$parentEntity = $this->runStoreParentFetchQuery($request, $parentQuery, $parentKey);
Expand Down Expand Up @@ -730,7 +730,7 @@ public function update(
): Resource|Response {
try {
$this->startTransaction();
$result = $this->updateWithTransaction($request, $parentKey, $relatedKey);
$result = $this->runUpdateOperation($request, $parentKey, $relatedKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -747,7 +747,7 @@ public function update(
* @return Resource|Response
* @throws BindingResolutionException
*/
protected function updateWithTransaction(
protected function runUpdateOperation(
Request $request,
string|int $parentKey,
string|int|null $relatedKey = null
Expand Down Expand Up @@ -966,7 +966,7 @@ public function destroy(
): Resource|Response {
try {
$this->startTransaction();
$result = $this->destroyWithTransaction($request, $parentKey, $relatedKey);
$result = $this->runDestroyOperation($request, $parentKey, $relatedKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -983,7 +983,7 @@ public function destroy(
* @return Resource|Response
* @throws BindingResolutionException
*/
protected function destroyWithTransaction(
protected function runDestroyOperation(
Request $request,
int|string $parentKey,
int|string|null $relatedKey = null
Expand Down Expand Up @@ -1167,7 +1167,7 @@ public function restore(
): Resource|Response {
try {
$this->startTransaction();
$result = $this->restoreWithTransaction($request, $parentKey, $relatedKey);
$result = $this->runRestoreOperation($request, $parentKey, $relatedKey);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -1184,7 +1184,7 @@ public function restore(
* @return Resource|Response
* @throws BindingResolutionException
*/
protected function restoreWithTransaction(
protected function runRestoreOperation(
Request $request,
int|string $parentKey,
int|string|null $relatedKey = null
Expand Down
16 changes: 8 additions & 8 deletions src/Concerns/HandlesStandardBatchOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function batchStore(Request $request): CollectionResource|AnonymousResour
{
try {
$this->startTransaction();
$result = $this->batchStoreWithTransaction($request);
$result = $this->runBatchStoreOperation($request);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -42,7 +42,7 @@ public function batchStore(Request $request): CollectionResource|AnonymousResour
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws BindingResolutionException
*/
protected function batchStoreWithTransaction(Request $request): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchStoreOperation(Request $request): CollectionResource|AnonymousResourceCollection|Response
{
$beforeHookResult = $this->beforeBatchStore($request);
if ($this->hookResponds($beforeHookResult)) {
Expand Down Expand Up @@ -134,7 +134,7 @@ public function batchUpdate(Request $request): CollectionResource|AnonymousResou
{
try {
$this->startTransaction();
$result = $this->batchUpdateWithTransaction($request);
$result = $this->runBatchUpdateOperation($request);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -149,7 +149,7 @@ public function batchUpdate(Request $request): CollectionResource|AnonymousResou
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws BindingResolutionException
*/
protected function batchUpdateWithTransaction(Request $request): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchUpdateOperation(Request $request): CollectionResource|AnonymousResourceCollection|Response
{
$beforeHookResult = $this->beforeBatchUpdate($request);
if ($this->hookResponds($beforeHookResult)) {
Expand Down Expand Up @@ -284,7 +284,7 @@ public function batchDestroy(Request $request): CollectionResource|AnonymousReso
{
try {
$this->startTransaction();
$result = $this->batchDestroyWithTransaction($request);
$result = $this->runBatchDestroyOperation($request);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -299,7 +299,7 @@ public function batchDestroy(Request $request): CollectionResource|AnonymousReso
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws BindingResolutionException
*/
protected function batchDestroyWithTransaction(Request $request): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchDestroyOperation(Request $request): CollectionResource|AnonymousResourceCollection|Response
{
$beforeHookResult = $this->beforeBatchDestroy($request);
if ($this->hookResponds($beforeHookResult)) {
Expand Down Expand Up @@ -412,7 +412,7 @@ public function batchRestore(Request $request): CollectionResource|AnonymousReso
{
try {
$this->startTransaction();
$result = $this->batchRestoreWithTransaction($request);
$result = $this->runBatchRestoreOperation($request);
$this->commitTransaction();
return $result;
} catch (Exception $exception) {
Expand All @@ -427,7 +427,7 @@ public function batchRestore(Request $request): CollectionResource|AnonymousReso
* @return CollectionResource|AnonymousResourceCollection|Response
* @throws Exception
*/
protected function batchRestoreWithTransaction(Request $request): CollectionResource|AnonymousResourceCollection|Response
protected function runBatchRestoreOperation(Request $request): CollectionResource|AnonymousResourceCollection|Response
{
$beforeHookResult = $this->beforeBatchRestore($request);
if ($this->hookResponds($beforeHookResult)) {
Expand Down
Loading

0 comments on commit cd2e6fd

Please sign in to comment.