client = $client; $this->credit = $credit; } public function run() { if ($this->credit->number != '') { return $this->credit; } $this->trySaving(); // $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); return $this->credit; } private function trySaving() { $x = 1; do { try { $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); $this->credit->saveQuietly(); $this->completed = false; } catch (QueryException $e) { $x++; if ($x > 50) { $this->completed = false; } } } while ($this->completed); } }