@andiliang One thing to keep in mind, and a good case to avoid nesting IFs, CHUNK big sections to individual methods. Also, when you are always returning something, that is a breakpoint and the code will not go any further, so you already do not need ALOT of if/else if. Try like this:
public function check()
{
// check job not started
if ($this->recruit->started()) {
return $this->gotEmployees[$this->recruit->gotEmployee()];
}
//if ever employee applied ths job
if ($this->recruit->appliedBy($this->user)) {
return $this->appliedBy();
}
return "apply job";
}
public function appliedBy()
{
// hired and approved by employer
if ($this->recruit->workingBy($this->user)) {
return $this->workingBy();
}
//if employyer are fired
if ($this->fired()) {
return "fired";
}
if ($this->cancelBy()) {
return "cancel";
}
if ($this->rejected()) {
return "rejected";
}
return "pending approval";
}
public function workingBy()
{
if ($this->recruit->noPunchIn()) {
if ($this->recruit->needAcceptance()) {
return $this->recruit->started() ? "wait for acceptance" : "wait for begin";
}
if ($this->recruit->noNeedAcceptance()) {
return $this->recruit->started() ? "wait for payout" : "wait for begin";
}
}
if ($this->needToSign()) {
return "punching in";
}
if ( $this->recruit->hiringCompleted() ) {
return "full";
}
return "waiting for start";
}
*edit to add some inline ternaries and condense one more if