| Conditions | 9 |
| Paths | 32 |
| Total Lines | 64 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 89 | private function update_oid_create() |
||
| 90 | { |
||
| 91 | // Insert data |
||
| 92 | |||
| 93 | $db_conn=$this->getTrapsDB()->db_connect_trap(); |
||
| 94 | $sql='INSERT INTO '.$this->getTrapsDB()->dbPrefix.'mib_cache '. |
||
| 95 | '(oid, name, type , mib, textual_convention, display_hint '. |
||
| 96 | ', syntax, type_enum , description ) ' . |
||
| 97 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
||
| 98 | ', :syntax, :type_enum, :description )'; |
||
| 99 | |||
| 100 | if ($this->getTrapsDB()->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
||
| 101 | |||
| 102 | $sqlQuery=$db_conn->prepare($sql); |
||
| 103 | |||
| 104 | $sqlParam=array( |
||
| 105 | ':oid' => $this->oidDesc['oid'], |
||
| 106 | ':name' => $this->oidDesc['name'], |
||
| 107 | ':type' => $this->oidDesc['type'], |
||
| 108 | ':mib' => $this->oidDesc['mib'], |
||
| 109 | ':tc' => $this->oidDesc['textconv']??'null', |
||
| 110 | ':display_hint' => $this->oidDesc['dispHint']??'null', |
||
| 111 | ':syntax' => $this->oidDesc['syntax']??'null', |
||
| 112 | ':type_enum' => $this->oidDesc['type_enum']??'null', |
||
| 113 | ':description' => $this->oidDesc['description']??'null' |
||
| 114 | ); |
||
| 115 | |||
| 116 | if ($sqlQuery->execute($sqlParam) === false) { |
||
| 117 | $this->getLogging()->log('Error in query : ' . $sql,1,''); |
||
| 118 | } |
||
| 119 | |||
| 120 | switch ($this->getTrapsDB()->trapDBType) |
||
| 121 | { |
||
| 122 | case 'pgsql': |
||
| 123 | // Get last id to insert oid/values in secondary table |
||
| 124 | if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) { |
||
| 125 | $this->getLogging()->log('Error getting id - pgsql - ',1,''); |
||
| 126 | } |
||
| 127 | if (! isset($inserted_id_ret['id'])) { |
||
| 128 | $this->getLogging()->log('Error getting id - pgsql - empty.',ERROR); |
||
| 129 | return 0; |
||
| 130 | } |
||
| 131 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id']; |
||
|
1 ignored issue
–
show
|
|||
| 132 | break; |
||
| 133 | case 'mysql': |
||
| 134 | // Get last id to insert oid/values in secondary table |
||
| 135 | $sql='SELECT LAST_INSERT_ID();'; |
||
| 136 | if (($ret_code=$db_conn->query($sql)) === false) { |
||
| 137 | $this->getLogging()->log('Erreur getting id - mysql - ',ERROR); |
||
| 138 | return 0; |
||
| 139 | } |
||
| 140 | |||
| 141 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
||
| 142 | if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
||
| 143 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
||
| 144 | break; |
||
| 145 | default: |
||
| 146 | $this->getLogging()->log('Error SQL type Unknown : '.$this->getTrapsDB()->trapDBType,ERROR); |
||
| 147 | return 0; |
||
| 148 | } |
||
| 149 | |||
| 150 | // Set as newly created. |
||
| 151 | $this->dbOidIndex[$this->oidDesc['oid']]['key']=-1; |
||
| 152 | return 2; |
||
| 153 | } |
||
| 180 | } |