it might sound stupid but i am having a hard time naming a function.
My function returns the id of the tag with the given $name parameter; but it should create a new tag if it doesn’t exist (and return the id of the new tag).
Here is my code:
public function get_tag_insert_if_not_exists($name)
{
$tag = $this->get_tag_with_name($name);
if ($tag === FALSE) {
return $this->insert_tag($name);
}
return $tag->id;
}
I think
getOrCreateis a more common name for this. Probably doesn’t make much of a difference, but I’ve seen this used more commonly thangetOrInsert.