public function savePost(PostEntity $post) { if ($post->hasId()) { $this->replacePost($post); } else { $this->insertPost($post); } }
public function savePost(PostEntity $post) { if (!$post->hasId()) { $post = $post->withId(uniqid()); } foreach ($this->posts as $idx => $existing) { if ($post->sameIdAs($existing)) { $this->posts[$idx] = $post; return; } } $this->posts[] = $post; }