Conditions | 11 |
Paths | 54 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
40 | public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = []) |
||
41 | { |
||
42 | if (! $this->initialized) { |
||
43 | $this->initializeTypes(); |
||
44 | } |
||
45 | |||
46 | if (! isset($params['pdo']) && ! isset($params['charset'])) { |
||
47 | $wrapperClass = null; |
||
48 | if (isset($params['wrapperClass'])) { |
||
49 | if (! is_subclass_of($params['wrapperClass'], Connection::class)) { |
||
|
|||
50 | throw DBALException::invalidWrapperClass($params['wrapperClass']); |
||
51 | } |
||
52 | |||
53 | $wrapperClass = $params['wrapperClass']; |
||
54 | $params['wrapperClass'] = null; |
||
55 | } |
||
56 | |||
57 | $connection = DriverManager::getConnection($params, $config, $eventManager); |
||
58 | $params = $connection->getParams(); |
||
59 | $driver = $connection->getDriver(); |
||
60 | |||
61 | if ($driver instanceof AbstractMySQLDriver) { |
||
62 | $params['charset'] = 'utf8mb4'; |
||
63 | |||
64 | if (! isset($params['defaultTableOptions']['collate'])) { |
||
65 | $params['defaultTableOptions']['collate'] = 'utf8mb4_unicode_ci'; |
||
66 | } |
||
67 | } else { |
||
68 | $params['charset'] = 'utf8'; |
||
69 | } |
||
70 | |||
71 | if ($wrapperClass !== null) { |
||
72 | $params['wrapperClass'] = $wrapperClass; |
||
73 | } else { |
||
74 | $wrapperClass = Connection::class; |
||
75 | } |
||
76 | |||
77 | $connection = new $wrapperClass($params, $driver, $config, $eventManager); |
||
78 | } else { |
||
79 | $connection = DriverManager::getConnection($params, $config, $eventManager); |
||
80 | } |
||
81 | |||
82 | if (! empty($mappingTypes)) { |
||
83 | $platform = $this->getDatabasePlatform($connection); |
||
84 | foreach ($mappingTypes as $dbType => $doctrineType) { |
||
85 | $platform->registerDoctrineTypeMapping($dbType, $doctrineType); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | return $connection; |
||
90 | } |
||
91 | |||
133 |