public function toggle(string $token, bool $force = null): bool
    {
        $this->tokenize();
        $isThereAfter = false;
        $i = array_search($token, $this->tokens);
        if (is_null($force)) {
            if ($i === false) {
                $this->tokens[] = $token;
                $isThereAfter = true;
            } else {
                array_splice($this->tokens, $i, 1);
            }
        } else {
            if ($force) {
                if ($i === false) {
                    $this->tokens[] = $token;
                }
                $isThereAfter = true;
            } else {
                if ($i !== false) {
                    array_splice($this->tokens, $i, 1);
                }
            }
        }
        $this->setAttributeValue();
        return $isThereAfter;
    }
public function toggle(string $token, bool $force = null): bool
    {
        $this->tokenize();
        $isThereAfter = false;
        $i = array_search($token, $this->tokens);
        if (is_null($force)) {
            if ($i === false) {
                $this->tokens[] = $token;
                $isThereAfter = true;
            } else {
                array_splice($this->tokens, $i, 1);
            }
        } else {
            if ($force) {
                if ($i === false) {
                    $this->tokens[] = $token;
                }
                $isThereAfter = true;
            } else {
                if ($i !== false) {
                    array_splice($this->tokens, $i, 1);
                }
            }
        }
        $this->setAttributeValue();
        return $isThereAfter;
    }
public function toggle ( string $ token , bool $ force = null ) : bool { $ this -> tokenize ( ) ; $ isThereAfter = false ; $ i = array_search ( $ token , $ this -> tokens ) ; if ( is_null ( $ force ) ) { if ( $ i === false ) { $ this -> tokens [ ] = $ token ; $ isThereAfter = true ; } else { array_splice ( $ this -> tokens , $ i , 1 ) ; } } else { if ( $ force ) { if ( $ i === false ) { $ this -> tokens [ ] = $ token ; } $ isThereAfter = true ; } else { if ( $ i !== false ) { array_splice ( $ this -> tokens , $ i , 1 ) ; } } } $ this -> setAttributeValue ( ) ; return $ isThereAfter ; }
Removes a given token from the list and returns false. If token doesn't exist it's added and the function returns true.

@param string $token The token you want to toggle.
@param bool $force A Boolean that, if included, turns the toggle into a one way-only operation. If set to false, the token will only be removed but not added again. If set to true, the token will only be added but not removed again.
@return bool false if the token is not in the list after the call, or true if the token is in the list after the call.
Removes a given token from the list and returns false . If token doesn t exist it s added and the function returns true .