Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like PostgreSqlPlatform often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PostgreSqlPlatform, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 59 | class PostgreSqlPlatform extends AbstractPlatform |
||
| 60 | { |
||
| 61 | /** |
||
| 62 | * @var bool |
||
| 63 | */ |
||
| 64 | private $useBooleanTrueFalseStrings = true; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var array PostgreSQL booleans literals |
||
| 68 | */ |
||
| 69 | private $booleanLiterals = [ |
||
| 70 | 'true' => [ |
||
| 71 | 't', |
||
| 72 | 'true', |
||
| 73 | 'y', |
||
| 74 | 'yes', |
||
| 75 | 'on', |
||
| 76 | '1' |
||
| 77 | ], |
||
| 78 | 'false' => [ |
||
| 79 | 'f', |
||
| 80 | 'false', |
||
| 81 | 'n', |
||
| 82 | 'no', |
||
| 83 | 'off', |
||
| 84 | '0' |
||
| 85 | ] |
||
| 86 | ]; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * PostgreSQL has different behavior with some drivers |
||
| 90 | * with regard to how booleans have to be handled. |
||
| 91 | * |
||
| 92 | * Enables use of 'true'/'false' or otherwise 1 and 0 instead. |
||
| 93 | * |
||
| 94 | * @param bool $flag |
||
| 95 | */ |
||
| 96 | public function setUseBooleanTrueFalseStrings($flag) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * {@inheritDoc} |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function getSubstringExpression($value, $from, $length = null) |
|
| 112 | |||
| 113 | /** |
||
| 114 | * {@inheritDoc} |
||
| 115 | */ |
||
| 116 | public function getNowExpression() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritDoc} |
||
| 123 | */ |
||
| 124 | public function getRegexpExpression() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritDoc} |
||
| 131 | */ |
||
| 132 | public function getLocateExpression($str, $substr, $startPos = false) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * {@inheritdoc} |
||
| 145 | */ |
||
| 146 | protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritDoc} |
||
| 158 | */ |
||
| 159 | public function getDateDiffExpression($date1, $date2) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritDoc} |
||
| 166 | */ |
||
| 167 | public function supportsSequences() |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritDoc} |
||
| 174 | */ |
||
| 175 | public function supportsSchemas() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | public function getDefaultSchemaName() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * {@inheritDoc} |
||
| 190 | */ |
||
| 191 | public function supportsIdentityColumns() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * {@inheritdoc} |
||
| 198 | */ |
||
| 199 | public function supportsPartialIndexes() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | public function usesSequenceEmulatedIdentityColumns() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * {@inheritdoc} |
||
| 214 | */ |
||
| 215 | public function getIdentitySequenceName($tableName, $columnName) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * {@inheritDoc} |
||
| 222 | */ |
||
| 223 | public function supportsCommentOnStatement() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * {@inheritDoc} |
||
| 230 | */ |
||
| 231 | public function prefersSequences() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * {@inheritDoc} |
||
| 238 | */ |
||
| 239 | public function hasNativeGuidType() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * {@inheritDoc} |
||
| 246 | */ |
||
| 247 | public function getListDatabasesSQL() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * {@inheritDoc} |
||
| 254 | */ |
||
| 255 | public function getListNamespacesSQL() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * {@inheritDoc} |
||
| 265 | */ |
||
| 266 | public function getListSequencesSQL($database) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * {@inheritDoc} |
||
| 277 | */ |
||
| 278 | public function getListTablesSQL() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * {@inheritDoc} |
||
| 292 | */ |
||
| 293 | public function getListViewsSQL($database) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * {@inheritDoc} |
||
| 304 | */ |
||
| 305 | public function getListTableForeignKeysSQL($table, $database = null) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * {@inheritDoc} |
||
| 320 | */ |
||
| 321 | public function getCreateViewSQL($name, $sql) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * {@inheritDoc} |
||
| 328 | */ |
||
| 329 | public function getDropViewSQL($name) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * {@inheritDoc} |
||
| 336 | */ |
||
| 337 | public function getListTableConstraintsSQL($table) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * {@inheritDoc} |
||
| 357 | * |
||
| 358 | * @license New BSD License |
||
| 359 | * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html |
||
| 360 | */ |
||
| 361 | public function getListTableIndexesSQL($table, $currentDatabase = null) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @param string $table |
||
| 376 | * @param string $classAlias |
||
| 377 | * @param string $namespaceAlias |
||
| 378 | * |
||
| 379 | * @return string |
||
| 380 | */ |
||
| 381 | private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n') |
||
| 397 | |||
| 398 | /** |
||
| 399 | * {@inheritDoc} |
||
| 400 | */ |
||
| 401 | public function getListTableColumnsSQL($table, $database = null) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * {@inheritDoc} |
||
| 437 | */ |
||
| 438 | public function getCreateDatabaseSQL($name) |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Returns the SQL statement for disallowing new connections on the given database. |
||
| 445 | * |
||
| 446 | * This is useful to force DROP DATABASE operations which could fail because of active connections. |
||
| 447 | * |
||
| 448 | * @param string $database The name of the database to disallow new connections for. |
||
| 449 | * |
||
| 450 | * @return string |
||
| 451 | */ |
||
| 452 | public function getDisallowDatabaseConnectionsSQL($database) |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Returns the SQL statement for closing currently active connections on the given database. |
||
| 459 | * |
||
| 460 | * This is useful to force DROP DATABASE operations which could fail because of active connections. |
||
| 461 | * |
||
| 462 | * @param string $database The name of the database to close currently active connections for. |
||
| 463 | * |
||
| 464 | * @return string |
||
| 465 | */ |
||
| 466 | public function getCloseActiveDatabaseConnectionsSQL($database) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * {@inheritDoc} |
||
| 475 | */ |
||
| 476 | public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * {@inheritDoc} |
||
| 505 | */ |
||
| 506 | public function getAlterTableSQL(TableDiff $diff) |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Checks whether a given column diff is a logically unchanged binary type column. |
||
| 640 | * |
||
| 641 | * Used to determine whether a column alteration for a binary type column can be skipped. |
||
| 642 | * Doctrine's {@link \Doctrine\DBAL\Types\BinaryType} and {@link \Doctrine\DBAL\Types\BlobType} |
||
| 643 | * are mapped to the same database column type on this platform as this platform |
||
| 644 | * does not have a native VARBINARY/BINARY column type. Therefore the {@link \Doctrine\DBAL\Schema\Comparator} |
||
| 645 | * might detect differences for binary type columns which do not have to be propagated |
||
| 646 | * to database as there actually is no difference at database level. |
||
| 647 | * |
||
| 648 | * @param ColumnDiff $columnDiff The column diff to check against. |
||
| 649 | * |
||
| 650 | * @return bool True if the given column diff is an unchanged binary type column, false otherwise. |
||
| 651 | */ |
||
| 652 | private function isUnchangedBinaryColumn(ColumnDiff $columnDiff) |
||
| 678 | |||
| 679 | /** |
||
| 680 | * {@inheritdoc} |
||
| 681 | */ |
||
| 682 | View Code Duplication | protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) |
|
| 691 | |||
| 692 | /** |
||
| 693 | * {@inheritdoc} |
||
| 694 | */ |
||
| 695 | View Code Duplication | public function getCommentOnColumnSQL($tableName, $columnName, $comment) |
|
| 704 | |||
| 705 | /** |
||
| 706 | * {@inheritDoc} |
||
| 707 | */ |
||
| 708 | View Code Duplication | public function getCreateSequenceSQL(Sequence $sequence) |
|
| 716 | |||
| 717 | /** |
||
| 718 | * {@inheritDoc} |
||
| 719 | */ |
||
| 720 | public function getAlterSequenceSQL(Sequence $sequence) |
||
| 726 | |||
| 727 | /** |
||
| 728 | * Cache definition for sequences |
||
| 729 | * |
||
| 730 | * @param Sequence $sequence |
||
| 731 | * |
||
| 732 | * @return string |
||
| 733 | */ |
||
| 734 | private function getSequenceCacheSQL(Sequence $sequence) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * {@inheritDoc} |
||
| 745 | */ |
||
| 746 | public function getDropSequenceSQL($sequence) |
||
| 754 | |||
| 755 | /** |
||
| 756 | * {@inheritDoc} |
||
| 757 | */ |
||
| 758 | public function getCreateSchemaSQL($schemaName) |
||
| 762 | |||
| 763 | /** |
||
| 764 | * {@inheritDoc} |
||
| 765 | */ |
||
| 766 | public function getDropForeignKeySQL($foreignKey, $table) |
||
| 770 | |||
| 771 | /** |
||
| 772 | * {@inheritDoc} |
||
| 773 | */ |
||
| 774 | protected function _getCreateTableSQL($tableName, array $columns, array $options = []) |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Converts a single boolean value. |
||
| 804 | * |
||
| 805 | * First converts the value to its native PHP boolean type |
||
| 806 | * and passes it to the given callback function to be reconverted |
||
| 807 | * into any custom representation. |
||
| 808 | * |
||
| 809 | * @param mixed $value The value to convert. |
||
| 810 | * @param callable $callback The callback function to use for converting the real boolean value. |
||
| 811 | * |
||
| 812 | * @return mixed |
||
| 813 | * @throws \UnexpectedValueException |
||
| 814 | */ |
||
| 815 | private function convertSingleBooleanValue($value, $callback) |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Converts one or multiple boolean values. |
||
| 845 | * |
||
| 846 | * First converts the value(s) to their native PHP boolean type |
||
| 847 | * and passes them to the given callback function to be reconverted |
||
| 848 | * into any custom representation. |
||
| 849 | * |
||
| 850 | * @param mixed $item The value(s) to convert. |
||
| 851 | * @param callable $callback The callback function to use for converting the real boolean value(s). |
||
| 852 | * |
||
| 853 | * @return mixed |
||
| 854 | */ |
||
| 855 | private function doConvertBooleans($item, $callback) |
||
| 867 | |||
| 868 | /** |
||
| 869 | * {@inheritDoc} |
||
| 870 | * |
||
| 871 | * Postgres wants boolean values converted to the strings 'true'/'false'. |
||
| 872 | */ |
||
| 873 | public function convertBooleans($item) |
||
| 890 | |||
| 891 | /** |
||
| 892 | * {@inheritDoc} |
||
| 893 | */ |
||
| 894 | public function convertBooleansToDatabaseValue($item) |
||
| 907 | |||
| 908 | /** |
||
| 909 | * {@inheritDoc} |
||
| 910 | */ |
||
| 911 | public function convertFromBoolean($item) |
||
| 919 | |||
| 920 | /** |
||
| 921 | * {@inheritDoc} |
||
| 922 | */ |
||
| 923 | public function getSequenceNextValSQL($sequenceName) |
||
| 927 | |||
| 928 | /** |
||
| 929 | * {@inheritDoc} |
||
| 930 | */ |
||
| 931 | public function getSetTransactionIsolationSQL($level) |
||
| 936 | |||
| 937 | /** |
||
| 938 | * {@inheritDoc} |
||
| 939 | */ |
||
| 940 | public function getBooleanTypeDeclarationSQL(array $field) |
||
| 944 | |||
| 945 | /** |
||
| 946 | * {@inheritDoc} |
||
| 947 | */ |
||
| 948 | public function getIntegerTypeDeclarationSQL(array $field) |
||
| 956 | |||
| 957 | /** |
||
| 958 | * {@inheritDoc} |
||
| 959 | */ |
||
| 960 | public function getBigIntTypeDeclarationSQL(array $field) |
||
| 968 | |||
| 969 | /** |
||
| 970 | * {@inheritDoc} |
||
| 971 | */ |
||
| 972 | public function getSmallIntTypeDeclarationSQL(array $field) |
||
| 976 | |||
| 977 | /** |
||
| 978 | * {@inheritDoc} |
||
| 979 | */ |
||
| 980 | public function getGuidTypeDeclarationSQL(array $field) |
||
| 984 | |||
| 985 | /** |
||
| 986 | * {@inheritDoc} |
||
| 987 | */ |
||
| 988 | public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) |
||
| 992 | |||
| 993 | /** |
||
| 994 | * {@inheritDoc} |
||
| 995 | */ |
||
| 996 | public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * {@inheritDoc} |
||
| 1003 | */ |
||
| 1004 | public function getDateTypeDeclarationSQL(array $fieldDeclaration) |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * {@inheritDoc} |
||
| 1011 | */ |
||
| 1012 | public function getTimeTypeDeclarationSQL(array $fieldDeclaration) |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * {@inheritDoc} |
||
| 1019 | * |
||
| 1020 | * @deprecated Use application-generated UUIDs instead |
||
| 1021 | */ |
||
| 1022 | public function getGuidExpression() |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * {@inheritDoc} |
||
| 1029 | */ |
||
| 1030 | protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * {@inheritDoc} |
||
| 1037 | */ |
||
| 1038 | protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) |
||
| 1043 | |||
| 1044 | /** |
||
| 1045 | * {@inheritdoc} |
||
| 1046 | */ |
||
| 1047 | protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * {@inheritDoc} |
||
| 1054 | */ |
||
| 1055 | public function getClobTypeDeclarationSQL(array $field) |
||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * {@inheritDoc} |
||
| 1062 | */ |
||
| 1063 | public function getName() |
||
| 1067 | |||
| 1068 | /** |
||
| 1069 | * {@inheritDoc} |
||
| 1070 | * |
||
| 1071 | * PostgreSQL returns all column names in SQL result sets in lowercase. |
||
| 1072 | */ |
||
| 1073 | public function getSQLResultCasing($column) |
||
| 1077 | |||
| 1078 | /** |
||
| 1079 | * {@inheritDoc} |
||
| 1080 | */ |
||
| 1081 | public function getDateTimeTzFormatString() |
||
| 1085 | |||
| 1086 | /** |
||
| 1087 | * {@inheritDoc} |
||
| 1088 | */ |
||
| 1089 | public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName) |
||
| 1093 | |||
| 1094 | /** |
||
| 1095 | * {@inheritDoc} |
||
| 1096 | */ |
||
| 1097 | public function getTruncateTableSQL($tableName, $cascade = false) |
||
| 1108 | |||
| 1109 | /** |
||
| 1110 | * {@inheritDoc} |
||
| 1111 | */ |
||
| 1112 | public function getReadLockSQL() |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * {@inheritDoc} |
||
| 1119 | */ |
||
| 1120 | View Code Duplication | protected function initializeDoctrineTypeMappings() |
|
| 1164 | |||
| 1165 | /** |
||
| 1166 | * {@inheritDoc} |
||
| 1167 | */ |
||
| 1168 | public function getVarcharMaxLength() |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * {@inheritdoc} |
||
| 1175 | */ |
||
| 1176 | public function getBinaryMaxLength() |
||
| 1180 | |||
| 1181 | /** |
||
| 1182 | * {@inheritdoc} |
||
| 1183 | */ |
||
| 1184 | public function getBinaryDefaultLength() |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * {@inheritDoc} |
||
| 1191 | */ |
||
| 1192 | protected function getReservedKeywordsClass() |
||
| 1196 | |||
| 1197 | /** |
||
| 1198 | * {@inheritDoc} |
||
| 1199 | */ |
||
| 1200 | public function getBlobTypeDeclarationSQL(array $field) |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * {@inheritdoc} |
||
| 1207 | */ |
||
| 1208 | public function quoteStringLiteral($str) |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * {@inheritdoc} |
||
| 1217 | */ |
||
| 1218 | public function getDefaultValueDeclarationSQL($field) |
||
| 1226 | |||
| 1227 | private function isSerialField(array $field) : bool |
||
| 1232 | |||
| 1233 | /** |
||
| 1234 | * Check whether the type of a column is changed in a way that invalidates the default value for the column |
||
| 1235 | * |
||
| 1236 | * @param ColumnDiff $columnDiff |
||
| 1237 | * @return bool |
||
| 1238 | */ |
||
| 1239 | private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff) : bool |
||
| 1252 | |||
| 1253 | private function isNumericType(Type $type) : bool |
||
| 1257 | } |
||
| 1258 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.