| Conditions | 4 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 32 |
| Lines | 34 |
| Ratio | 62.96 % |
| Changes | 1 | ||
| 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 | $ezContext = new \Aimeos\MShop\Context\Item\Ezpublish(); |
||
| 86 | $ezContext->setDatabaseManager( clone $context->getDatabaseManager() ); |
||
| 87 | $ezContext->setSession( clone $context->getSession() ); |
||
| 88 | $ezContext->setLogger( clone $context->getLogger() ); |
||
| 89 | $ezContext->setLocale( clone $context->getLocale() ); |
||
| 90 | $ezContext->setConfig( clone $context->getConfig() ); |
||
| 91 | $ezContext->setCache( clone $context->getCache() ); |
||
| 92 | |||
| 93 | $task = $this; |
||
|
|
|||
| 94 | |||
| 95 | View Code Duplication | $ezContext->setEzUser( function( $code, $email, $password ) use ( $context ) { |
|
| 96 | |||
| 97 | $id = mt_rand( -0x7fffffff,-1 ); |
||
| 98 | $dbm = $context->getDatabaseManager(); |
||
| 99 | $dbconf = $context->getConfig()->get( 'resource/db-customer' ); |
||
| 100 | $dbname = ( $dbconf ? 'db-customer' : 'db' ); |
||
| 101 | $conn = $dbm->acquire( $dbname ); |
||
| 102 | |||
| 103 | try |
||
| 104 | { |
||
| 105 | $stmt = $conn->create( 'INSERT INTO "ezuser" ( |
||
| 106 | "contentobject_id", "email", "login", "login_normalized", "password_hash", "password_hash_type" |
||
| 107 | ) VALUES ( |
||
| 108 | ?, ?, ?, ?, ?, 5 |
||
| 109 | )' ); |
||
| 110 | |||
| 111 | $stmt->bind( 1, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
| 112 | $stmt->bind( 2, $email ); |
||
| 113 | $stmt->bind( 3, $code ); |
||
| 114 | $stmt->bind( 4, $code ); |
||
| 115 | $stmt->bind( 5, $password ); |
||
| 116 | |||
| 117 | $stmt->execute()->finish(); |
||
| 118 | |||
| 119 | $dbm->release( $conn, $dbname ); |
||
| 120 | } |
||
| 121 | catch( \Exception $e ) |
||
| 122 | { |
||
| 123 | $dbm->release( $conn, $dbname ); |
||
| 124 | throw $e; |
||
| 125 | } |
||
| 126 | |||
| 127 | return $id; |
||
| 128 | } ); |
||
| 129 | |||
| 130 | return $ezContext; |
||
| 131 | } |
||
| 132 | } |
||
| 133 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.