| Conditions | 8 |
| Paths | 156 |
| Total Lines | 52 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 94 | * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond |
||
| 95 | */ |
||
| 96 | public function setMultiple( $pairs, $expires = null, array $tags = array() ) |
||
| 97 | { |
||
| 98 | $type = ( count( $pairs ) > 1 ? \Aimeos\MW\DB\Connection\Base::TYPE_PREP : \Aimeos\MW\DB\Connection\Base::TYPE_SIMPLE ); |
||
| 99 | $conn = $this->dbm->acquire( $this->dbname ); |
||
| 100 | |||
| 101 | try |
||
| 102 | { |
||
| 103 | $conn->begin(); |
||
| 104 | $stmt = $conn->create( $this->sql['set'], $type ); |
||
| 105 | |||
| 106 | foreach( $pairs as $key => $value ) |
||
| 107 | { |
||
| 108 | $date = ( isset( $expires[$key] ) ? $expires[$key] : null ); |
||
| 109 | |||
| 110 | $stmt->bind( 1, $key ); |
||
| 111 | $stmt->bind( 2, $this->siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
| 112 | $stmt->bind( 3, $date ); |
||
| 113 | $stmt->bind( 4, $value ); |
||
| 114 | $stmt->execute()->finish(); |
||
| 115 | |||
| 116 | if( isset( $tags[$key] ) ) |
||
| 117 | { |
||
| 118 | $parts = array(); |
||
| 119 | $stmtTagPart = $conn->create( '( ?, ?, ? )' ); |
||
| 120 | |||
| 121 | foreach( (array) $tags[$key] as $name ) |
||
| 122 | { |
||
| 123 | $stmtTagPart->bind( 1, $key ); |
||
| 124 | $stmtTagPart->bind( 2, $this->siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
| 125 | $stmtTagPart->bind( 3, $name ); |
||
| 126 | |||
| 127 | $parts[] = (string) $stmtTagPart; |
||
| 128 | } |
||
| 129 | |||
| 130 | if( !empty ( $parts ) ) |
||
| 131 | { |
||
| 132 | $stmtTag = $conn->create( str_replace( ':tuples', join( ',', $parts ), $this->sql['settag'] ) ); |
||
| 133 | $stmtTag->execute()->finish(); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | $conn->commit(); |
||
| 139 | $this->dbm->release( $conn, $this->dbname ); |
||
| 140 | } |
||
| 141 | catch( \Exception $e ) |
||
| 142 | { |
||
| 143 | $conn->rollback(); |
||
| 144 | $this->dbm->release( $conn, $this->dbname ); |
||
| 145 | throw $e; |
||
| 146 | } |
||
| 149 |