| Conditions | 3 |
| Paths | 3 |
| Total Lines | 51 |
| Code Lines | 34 |
| 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 |
||
| 60 | public static function createConnection( |
||
| 61 | string $dbDriver, |
||
| 62 | ?string $dbHost = null, |
||
| 63 | ?string $dbPort = null, |
||
| 64 | ?string $dbUserName = null, |
||
| 65 | ?string $dbPassword = null, |
||
| 66 | ?string $dbName = null |
||
| 67 | ): Connection { |
||
| 68 | $config = new \Doctrine\DBAL\Configuration(); |
||
| 69 | |||
| 70 | $dbDriver = $dbDriver; |
||
| 71 | |||
| 72 | if ($dbDriver === 'pdo_sqlite') { |
||
| 73 | $connectionParams = array( |
||
| 74 | 'memory' => true, |
||
| 75 | 'driver' => 'pdo_sqlite', |
||
| 76 | ); |
||
| 77 | $dbConnection = DriverManager::getConnection($connectionParams, $config); |
||
| 78 | } elseif ($dbDriver === 'oci8') { |
||
| 79 | $evm = new EventManager(); |
||
| 80 | $evm->addEventSubscriber(new OracleSessionInit(array( |
||
| 81 | 'NLS_TIME_FORMAT' => 'HH24:MI:SS', |
||
| 82 | 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', |
||
| 83 | 'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', |
||
| 84 | ))); |
||
| 85 | |||
| 86 | $connectionParams = array( |
||
| 87 | 'servicename' => 'XE', |
||
| 88 | 'user' => $dbUserName, |
||
| 89 | 'password' => $dbPassword, |
||
| 90 | 'host' => $dbHost, |
||
| 91 | 'port' => $dbPort, |
||
| 92 | 'driver' => $dbDriver, |
||
| 93 | 'dbname' => $dbName, |
||
| 94 | 'charset' => 'AL32UTF8', |
||
| 95 | ); |
||
| 96 | $dbConnection = DriverManager::getConnection($connectionParams, $config, $evm); |
||
| 97 | $dbConnection->setAutoCommit(true); |
||
| 98 | } else { |
||
| 99 | $connectionParams = array( |
||
| 100 | 'user' => $dbUserName, |
||
| 101 | 'password' => $dbPassword, |
||
| 102 | 'host' => $dbHost, |
||
| 103 | 'port' => $dbPort, |
||
| 104 | 'driver' => $dbDriver, |
||
| 105 | 'dbname' => $dbName, |
||
| 106 | ); |
||
| 107 | $dbConnection = DriverManager::getConnection($connectionParams, $config); |
||
| 108 | } |
||
| 109 | |||
| 110 | return $dbConnection; |
||
| 111 | } |
||
| 113 |
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.