Conditions | 10 |
Paths | 604 |
Total Lines | 56 |
Code Lines | 32 |
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 |
||
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 = ( is_array( $expires ) && isset( $expires[$key] ) ? $expires[$key] : $expires ); |
||
109 | |||
110 | if( is_int( $date ) ) { |
||
111 | $date = date( 'Y-m-d H:i:s', time() + $date ); |
||
112 | } |
||
113 | |||
114 | $stmt->bind( 1, $key ); |
||
115 | $stmt->bind( 2, $this->siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
116 | $stmt->bind( 3, $date ); |
||
117 | $stmt->bind( 4, $value ); |
||
118 | $stmt->execute()->finish(); |
||
119 | |||
120 | if( isset( $tags[$key] ) ) |
||
121 | { |
||
122 | $parts = array(); |
||
123 | $stmtTagPart = $conn->create( '( ?, ?, ? )' ); |
||
124 | |||
125 | foreach( (array) $tags[$key] as $name ) |
||
126 | { |
||
127 | $stmtTagPart->bind( 1, $key ); |
||
128 | $stmtTagPart->bind( 2, $this->siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
129 | $stmtTagPart->bind( 3, $name ); |
||
130 | |||
131 | $parts[] = (string) $stmtTagPart; |
||
132 | } |
||
133 | |||
134 | if( !empty ( $parts ) ) |
||
135 | { |
||
136 | $stmtTag = $conn->create( str_replace( ':tuples', join( ',', $parts ), $this->sql['settag'] ) ); |
||
137 | $stmtTag->execute()->finish(); |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | $conn->commit(); |
||
143 | $this->dbm->release( $conn, $this->dbname ); |
||
144 | } |
||
145 | catch( \Exception $e ) |
||
146 | { |
||
147 | $conn->rollback(); |
||
148 | $this->dbm->release( $conn, $this->dbname ); |
||
149 | throw $e; |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 |