简体   繁体   中英

camelCase parameters in setter in PhpStorm

I have under_score named properties in my class like transaction_id or web_order_item_id . And I want to customize the parameter name in my setters when I generate it.

For now it generate this:

/**
 * @param int $original_transaction_id .camelCase()
 */
public function setOriginalTransactionId(int $original_transaction_id): void
{
    $this->original_transaction_id = $original_transaction_id;
}

But I want this:

/**
 * @param int $originalTransactionId .camelCase()
 */
public function setOriginalTransactionId(int $originalTransactionId): void
{
    $this->original_transaction_id = $originalTransactionId;
}

I have tried to change this behavior in Settings/Editor/File and Code Templates/Code/Php Setter Method but I couldn`t found ability to do it. There is a variable in the template:

${NAME}

But it returned value in this form $OriginalTransactionId instead $originalTransactionId

You can try using Apache Velocity StringUtils here, like

#set($Setter_param = ${StringUtils.removeAndHump(${PARAM_NAME})})
#set($Setter_param = $Setter_param.substring(0,1).toLowerCase() + $Setter_param.substring(1))

/**
 * @param ${TYPE_HINT} $${Setter_param}
 */
public ${STATIC} function set${NAME}(#if (${SCALAR_TYPE_HINT})${SCALAR_TYPE_HINT} #end$${Setter_param})#if (${VOID_RETURN_TYPE}):void #end
{
#if (${STATIC} == "static")
    self::$${FIELD_NAME} = $${Setter_param};
#else
    $this->${FIELD_NAME} = $${Setter_param};
#end
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM