Here is a sample code of how to write something based on email, session key, and message. I use most of the code in error handling, like this:
First, I need check null, then, the length, session, connection with db, lastly, the actually result.... ....It is very ignoring, and the code become very long, how can I simify this? Thank you.
if(checkNullExisit($aEmail, $aSessionKey, $aMessage)){
//Null params detect
return;
}
if(strlen($aEmail) > MAX_EMAIL || strlen($aSessionKey) > MAX_SESSIONKEY || strlen($aMessage) > MAX_MESSAGE){
//Too long
return;
}
if(isSessionValid($aEmail, $aSessionKey)){
if(connectDatabase()){
if(DBManagerSingleton::saveMessage($aEmail, $aSessionKey, $aMessage, NULL)){
//The ONLY Success Case
return;
}else{
//Can't write in DB
return;
}
}else{
//DB Cannot Connect
return;
}
}else{
//Invalid Session
return;
}