Reduce sonar complexity (#992)
This commit is contained in:
@@ -37,28 +37,9 @@ class ApiAddressController extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Validates basic fields to create the entry
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'max:255|required',
|
||||
'street' => 'max:255|nullable',
|
||||
'city' => 'max:255|nullable',
|
||||
'province' => 'max:255|nullable',
|
||||
'postal_code' => 'max:255|nullable',
|
||||
'country_id' => 'integer|nullable',
|
||||
'contact_id' => 'required|integer',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->setErrorCode(32)
|
||||
->respondWithError($validator->errors()->all());
|
||||
}
|
||||
|
||||
try {
|
||||
Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $request->input('contact_id'))
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
$isvalid = $this->validateUpdate($request);
|
||||
if ($isvalid !== true) {
|
||||
return $isvalid;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -91,6 +72,28 @@ class ApiAddressController extends ApiController
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
$isvalid = $this->validateUpdate($request);
|
||||
if ($isvalid !== true) {
|
||||
return $isvalid;
|
||||
}
|
||||
|
||||
try {
|
||||
$address->update($request->all());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondNotTheRightParameters();
|
||||
}
|
||||
|
||||
return new AddressResource($address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the request for update.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
private function validateUpdate(Request $request)
|
||||
{
|
||||
// Validates basic fields to create the entry
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'max:255|required',
|
||||
@@ -115,13 +118,7 @@ class ApiAddressController extends ApiController
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$address->update($request->all());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondNotTheRightParameters();
|
||||
}
|
||||
|
||||
return new AddressResource($address);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user