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 |
||
76 | public static function createConnection( |
||
77 | string $dbDriver, |
||
78 | ?string $dbHost = null, |
||
79 | ?string $dbPort = null, |
||
80 | ?string $dbUserName = null, |
||
81 | ?string $dbPassword = null, |
||
82 | ?string $dbName = null |
||
83 | ): Connection { |
||
84 | $config = new \Doctrine\DBAL\Configuration(); |
||
85 | |||
86 | $dbDriver = $dbDriver; |
||
87 | |||
88 | if ($dbDriver === 'pdo_sqlite') { |
||
89 | $connectionParams = array( |
||
90 | 'memory' => true, |
||
91 | 'driver' => 'pdo_sqlite', |
||
92 | ); |
||
93 | $dbConnection = DriverManager::getConnection($connectionParams, $config); |
||
94 | } elseif ($dbDriver === 'oci8') { |
||
95 | $evm = new EventManager(); |
||
96 | $evm->addEventSubscriber(new OracleSessionInit(array( |
||
97 | 'NLS_TIME_FORMAT' => 'HH24:MI:SS', |
||
98 | 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', |
||
99 | 'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', |
||
100 | ))); |
||
101 | |||
102 | $connectionParams = array( |
||
103 | 'servicename' => 'XE', |
||
104 | 'user' => $dbUserName, |
||
105 | 'password' => $dbPassword, |
||
106 | 'host' => $dbHost, |
||
107 | 'port' => $dbPort, |
||
108 | 'driver' => $dbDriver, |
||
109 | 'dbname' => $dbName, |
||
110 | 'charset' => 'AL32UTF8', |
||
111 | ); |
||
112 | $dbConnection = DriverManager::getConnection($connectionParams, $config, $evm); |
||
113 | $dbConnection->setAutoCommit(true); |
||
114 | } else { |
||
115 | $connectionParams = array( |
||
116 | 'user' => $dbUserName, |
||
117 | 'password' => $dbPassword, |
||
118 | 'host' => $dbHost, |
||
119 | 'port' => $dbPort, |
||
120 | 'driver' => $dbDriver, |
||
121 | 'dbname' => $dbName, |
||
122 | ); |
||
123 | $dbConnection = DriverManager::getConnection($connectionParams, $config); |
||
124 | } |
||
125 | |||
126 | return $dbConnection; |
||
127 | } |
||
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.