开发者

How should i name a function that retrieves smt but inserts it if it doesn't exists [closed]

开发者 https://www.devze.com 2023-03-19 03:11 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing th
Closed. This question is opinion-based. It is not currently accepting answers.

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 question

it 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();

0

精彩评论

暂无评论...
验证码 换一张
取 消