| Conditions | 3 |
| Paths | 3 |
| Total Lines | 57 |
| Code Lines | 31 |
| 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 |
||
| 17 | public static function resetDatabase( |
||
| 18 | string $dbDriver, |
||
| 19 | ?string $dbHost = null, |
||
| 20 | ?string $dbPort = null, |
||
| 21 | ?string $dbUserName = null, |
||
| 22 | ?string $dbAdminUserName = null, |
||
| 23 | ?string $dbPassword = null, |
||
| 24 | ?string $dbName = null |
||
| 25 | ): Connection { |
||
| 26 | $config = new \Doctrine\DBAL\Configuration(); |
||
| 27 | |||
| 28 | $dbDriver = $dbDriver; |
||
| 29 | |||
| 30 | if ($dbDriver === 'pdo_sqlite') { |
||
| 31 | $dbConnection = self::getConnection(); |
||
|
|
|||
| 32 | $dbConnection->exec('PRAGMA foreign_keys = ON;'); |
||
| 33 | } elseif ($dbDriver === 'oci8') { |
||
| 34 | $connectionParams = array( |
||
| 35 | 'servicename' => 'XE', |
||
| 36 | 'user' => $dbAdminUserName, |
||
| 37 | // Because of issues in DBAL, admin and normal user password have to be the same. |
||
| 38 | 'password' => $dbPassword, |
||
| 39 | 'host' => $dbHost, |
||
| 40 | 'port' => $dbPort, |
||
| 41 | 'driver' => $dbDriver, |
||
| 42 | 'dbname' => $dbAdminUserName, |
||
| 43 | 'charset' => 'AL32UTF8', |
||
| 44 | ); |
||
| 45 | |||
| 46 | $adminConn = DriverManager::getConnection($connectionParams, $config); |
||
| 47 | |||
| 48 | // When dropAndCreateDatabase is run several times, Oracle can have some issues releasing the TDBM user. |
||
| 49 | // Let's forcefully delete the connection! |
||
| 50 | $adminConn->exec("select 'alter system kill session ''' || sid || ',' || serial# || ''';' from v\$session where username = '".strtoupper($dbName)."'"); |
||
| 51 | |||
| 52 | $adminConn->getSchemaManager()->dropAndCreateDatabase($dbName); |
||
| 53 | |||
| 54 | $dbConnection = self::getConnection(); |
||
| 55 | } else { |
||
| 56 | $connectionParams = array( |
||
| 57 | 'user' => $dbUserName, |
||
| 58 | 'password' => $dbPassword, |
||
| 59 | 'host' => $dbHost, |
||
| 60 | 'port' => $dbPort, |
||
| 61 | 'driver' => $dbDriver, |
||
| 62 | ); |
||
| 63 | |||
| 64 | $adminConn = DriverManager::getConnection($connectionParams, $config); |
||
| 65 | |||
| 66 | $adminConn->getSchemaManager()->dropAndCreateDatabase($dbName); |
||
| 67 | |||
| 68 | $connectionParams['dbname'] = $dbName; |
||
| 69 | |||
| 70 | $dbConnection = DriverManager::getConnection($connectionParams, $config); |
||
| 71 | } |
||
| 72 | |||
| 73 | return $dbConnection; |
||
| 74 | } |
||
| 129 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.