interview test
<?php
/**
* Please refactor and optimize the following piece of code.
*
* Note: Everything that comes in, comes out or being used inside of that function can be changed as well.
* We will consider that all levels of the application were refactored along with this
* particular method.
*/
public function activate($email, $hash)
{
if(!empty($email) && !empty($hash))
{
try
{
$auth_api = $this->getClient()->api('auth');
$response = $auth_api->activate([
'email' => $email,
'hash' => $hash
]);
if(isset($response['error']))
{
Log::error('Invalid argument passed to client. '.$e->getMessage());
return false;
}
else
{
return $response;
}
}
catch(InvalidArgumentException $e)
{
Log::error('Invalid argument passed to client. '.$e->getMessage());
Log::debug($e->getTraceAsString());
}
catch (MissingArgumentException $e)
{
Log::error('Missing argument in activate. '.$e->getMessage());
Log::debug($e->getTraceAsString());
}
catch(IDPException $e)
{
Log::error('Error while retrieving token. '.$e->getMessage());
Log::debug($e->getTraceAsString());
}
catch (Exception $e)
{
Log::error($e->getMessage());
Log::debug($e->getTraceAsString());
}
}
return false;
}