best name for this method in php

Asked

Viewed 34 times

-4

I’m doubtful what name to put in the PHP method below:

    public function checkbox($idForm)
    {
        $list = $this->v->getAllInAssocArr();

        foreach ($list as $key => $val) {

            $isRel = $this->v->isRel($idForm, $key);

            if (self::isPost($key) && !$isRel) {
                $this->v->insert($idForm, $key);
            } 

            
            if (!self::isPost($key) && $isRel){
                $this->v->delete($idForm, $key);
            } 
        }

    } 

It add or remove Data in DB as selected posts in the form checkbox. thought I’d put "updateCheckboxByIdForm" but it does not update

  • What do you mean by "it doesn’t update"? You can put the name you want. In my opinion, "updateCheckboxByIdForm" means nothing better than the original name. Depends on the form for being "checkbox_signup" or "checkbox_client" etc...

  • about "does not update" . I meant that the method was not done to update the data. just "inserts" or "removes" so I found it strange to put "update ..." as the name for the method ...

1 answer

0

Hello, welcome. I believe the name updateCheckboxById as you yourself mentioned is a good name.

I always follow a pattern of starting by verbalizing what it will do, followed by the object plus the action of that method:

Ex: getUserClear()

    public function updateCheckboxById($idForm)
    {
        $list = $this->v->getAllInAssocArr();

        foreach ($list as $key => $val) {
            $isRel = $this->v->isRel($idForm, $key);
            if (self::isPost($key) && !$isRel) {
                $this->v->insert($idForm, $key);
            } 
            if (!self::isPost($key) && $isRel){
                $this->v->delete($idForm, $key);
            } 
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.