| Conditions | 7 |
| Paths | 2 |
| Total Lines | 69 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 78 | protected function getEzContext( \Aimeos\MShop\Context\Item\Iface $context ) |
||
| 79 | { |
||
| 80 | $class = '\Aimeos\MShop\Context\Item\Ezpublish'; |
||
| 81 | if( is_a( $context, $class ) ) { |
||
| 82 | return $context; |
||
| 83 | } |
||
| 84 | |||
| 85 | $ctx = new \Aimeos\MShop\Context\Item\Ezpublish(); |
||
| 86 | $ctx->setDatabaseManager( clone $context->getDatabaseManager() ); |
||
| 87 | $ctx->setSession( clone $context->getSession() ); |
||
| 88 | $ctx->setLogger( clone $context->getLogger() ); |
||
| 89 | $ctx->setLocale( clone $context->getLocale() ); |
||
| 90 | $ctx->setConfig( clone $context->getConfig() ); |
||
| 91 | $ctx->setCache( clone $context->getCache() ); |
||
| 92 | |||
| 93 | |||
| 94 | $ctx->setEzUser( function( $id, $code, $email, $password, $status ) use ( $ctx ) { |
||
| 95 | |||
| 96 | $dbm = $ctx->getDatabaseManager(); |
||
| 97 | $dbname = ( $ctx->getConfig()->get( 'resource/db-customer' ) ? 'db-customer' : 'db' ); |
||
| 98 | $conn = $dbm->acquire( $dbname ); |
||
| 99 | |||
| 100 | try |
||
| 101 | { |
||
| 102 | $contentid = ( $id === null ? mt_rand( -0x7fffffff,-1 ) : $id ); |
||
| 103 | |||
| 104 | if( $id === null ) { |
||
| 105 | $sql = 'INSERT INTO "ezuser" ( "email", "login", "login_normalized", "password_hash", "password_hash_type", "contentobject_id" ) VALUES ( ?, ?, ?, ?, 5, ? )'; |
||
| 106 | } else { |
||
| 107 | $sql = 'UPDATE "ezuser" SET "email" = ?, "login" = ?, "login_normalized" = ?, "password_hash" = ?, "password_hash_type" = 5 WHERE "contentobject_id" = ?'; |
||
| 108 | } |
||
| 109 | |||
| 110 | $stmt = $conn->create( $sql ); |
||
| 111 | $stmt->bind( 1, $email ); |
||
| 112 | $stmt->bind( 2, $code ); |
||
| 113 | $stmt->bind( 3, $code ); |
||
| 114 | $stmt->bind( 4, $password ); |
||
| 115 | $stmt->bind( 5, $contentid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
| 116 | |||
| 117 | $stmt->execute()->finish(); |
||
| 118 | |||
| 119 | |||
| 120 | if( $id === null ) { |
||
| 121 | $sql = 'INSERT INTO "ezuser_setting" ( "is_enabled", "user_id" ) VALUES ( ?, ? )'; |
||
| 122 | } else { |
||
| 123 | $sql = 'UPDATE "ezuser_setting" SET "is_enabled" = ? WHERE "user_id" = ?'; |
||
| 124 | } |
||
| 125 | |||
| 126 | $stmt = $conn->create( $sql ); |
||
| 127 | $stmt->bind( 1, $status, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
| 128 | $stmt->bind( 2, $contentid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
| 129 | |||
| 130 | $stmt->execute()->finish(); |
||
| 131 | |||
| 132 | |||
| 133 | $dbm->release( $conn, $dbname ); |
||
| 134 | } |
||
| 135 | catch( \Exception $e ) |
||
| 136 | { |
||
| 137 | $dbm->release( $conn, $dbname ); |
||
| 138 | throw $e; |
||
| 139 | } |
||
| 140 | |||
| 141 | return $contentid; |
||
| 142 | } ); |
||
| 143 | |||
| 144 | |||
| 145 | return $ctx; |
||
| 146 | } |
||
| 147 | } |
||
| 148 |