manticoresearch-php icon indicating copy to clipboard operation
manticoresearch-php copied to clipboard

Unnecessary line in class Create

Open oam333 opened this issue 4 years ago • 1 comments

Method "setBody" of class "Create" has unnecessary line # 37 (of origin file /phpClient/vendor/manticoresoftware/manticoresearch-php/src/Manticoresearch/Endpoints/Indices/Create.php).

See comment inside code:

public function setBody($params = null)
{
    if (isset($this->index)) {
        $columns = [];
        if (isset($params['columns'])) {
            foreach ($params['columns'] as $name => $settings) {
                $column = $name . ' ' . $settings['type'];
                if (isset($settings['options']) && count($settings['options']) > 0) {
                    $column .= ' ' . implode(' ', $settings['options']);
                }
                $columns[] = $column;
            }
        }
        $options = "";
        if (isset($params['settings'])) {
            foreach ($params['settings'] as $name => $value) {
                $options.=" ".$name." = '".$value."'";       // ##### <----- this line is unneccessary, because the same code lower in "else" block
                if (is_array($value)) {
                    foreach ($value as $v) {
                        $options.=" ".$name." = '".$v."'";
                    }
                } else {
                    $options.=" ".$name." = '".$value."'"; // #### <----- the same code
                }
            }
        }
        return parent::setBody(['query' => "CREATE TABLE ".
            (isset($params['silent']) && $params['silent']===true?' IF NOT EXISTS ':'').
            $this->index.
            (count($columns)>0?"(".implode(",", $columns).")":" ")
            .$options]);
    }
    throw new RuntimeException('Index name is missing.');
}

oam333 avatar Nov 23 '21 09:11 oam333

Hello @oam333

Thank you for this issue. We'll be glad to accept your pull request.

sanikolaev avatar Nov 24 '21 04:11 sanikolaev