How should i name a function that retrieves smt but inserts it if it doesn't exists [closed]
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this questionit migh开发者_JAVA百科t 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 getOrCreate
is a more common name for this. Probably doesn't make much of a difference, but I've seen this used more commonly than getOrInsert
.
getInsertTag();
or more verbous/uglier
getOrInsertTag();
精彩评论