| Conditions | 10 |
| Paths | 13 |
| Total Lines | 46 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 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 |
||
| 78 | public function generateIdentifierName( |
||
| 79 | $tableNames, |
||
| 80 | $columnNames, |
||
| 81 | $prefix = '', |
||
| 82 | $upperCase = null, |
||
| 83 | $forceHash = false |
||
| 84 | ) { |
||
| 85 | if (empty($tableNames) || (is_array($tableNames) && count($tableNames) === 1 && empty($tableNames[0]))) { |
||
| 86 | throw new \InvalidArgumentException('A table name must not be empty.'); |
||
| 87 | } |
||
| 88 | if (!is_array($tableNames)) { |
||
| 89 | $tableNames = [$tableNames]; |
||
| 90 | } |
||
| 91 | |||
| 92 | if (!$forceHash) { |
||
| 93 | $columns = implode('_', $columnNames); |
||
| 94 | $tables = implode('_', $tableNames); |
||
| 95 | if (strlen($prefix) + strlen($tables) + strlen($columns) + 2 <= $this->getMaxIdentifierSize()) { |
||
| 96 | $result = $prefix . '_' . $tables . '_' . $columns; |
||
| 97 | |||
| 98 | return $upperCase === true ? strtoupper($result) : strtolower($result); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | $result = $prefix . '_' . |
||
| 103 | implode( |
||
| 104 | '', |
||
| 105 | array_merge( |
||
| 106 | array_map( |
||
| 107 | function ($name) { |
||
| 108 | return dechex(crc32($name)); |
||
| 109 | }, |
||
| 110 | $tableNames |
||
| 111 | ), |
||
| 112 | array_map( |
||
| 113 | function ($name) { |
||
| 114 | return dechex(crc32($name)); |
||
| 115 | }, |
||
| 116 | $columnNames |
||
| 117 | ) |
||
| 118 | ) |
||
| 119 | ); |
||
| 120 | $result = substr($result, 0, $this->getMaxIdentifierSize()); |
||
| 121 | |||
| 122 | return $upperCase === false ? strtolower($result) : strtoupper($result); |
||
| 123 | } |
||
| 124 | } |
||
| 125 |