| Conditions | 31 |
| Paths | 466 |
| Total Lines | 127 |
| Code Lines | 100 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| 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 |
||
| 81 | private function synchronizeDbModel(AbstractZohoDao $dao) |
||
| 82 | { |
||
| 83 | $tableName = $this->getTableName($dao); |
||
| 84 | $this->logger->info("Synchronizing DB Model for ".$tableName); |
||
| 85 | |||
| 86 | $schema = new Schema(); |
||
| 87 | $table = $schema->createTable($tableName); |
||
| 88 | |||
| 89 | $flatFields = $this->getFlatFields($dao->getFields()); |
||
|
|
|||
| 90 | |||
| 91 | $table->addColumn('id', 'string', ['length' => 100]); |
||
| 92 | $table->setPrimaryKey(['id']); |
||
| 93 | |||
| 94 | foreach ($flatFields as $field) { |
||
| 95 | $columnName = $field['name']; |
||
| 96 | |||
| 97 | $length = null; |
||
| 98 | $index = false; |
||
| 99 | |||
| 100 | // Note: full list of types available here: https://www.zoho.com/crm/help/customization/custom-fields.html |
||
| 101 | switch ($field['type']) { |
||
| 102 | case 'Lookup ID': |
||
| 103 | case 'Lookup': |
||
| 104 | $type = 'string'; |
||
| 105 | $length = 100; |
||
| 106 | $index = true; |
||
| 107 | break; |
||
| 108 | case 'OwnerLookup': |
||
| 109 | $type = 'string'; |
||
| 110 | $index = true; |
||
| 111 | $length = 25; |
||
| 112 | break; |
||
| 113 | case 'Formula': |
||
| 114 | // Note: a Formula can return any type, but we have no way to know which type it returns... |
||
| 115 | $type = 'string'; |
||
| 116 | $length = 100; |
||
| 117 | break; |
||
| 118 | case 'DateTime': |
||
| 119 | $type = 'datetime'; |
||
| 120 | break; |
||
| 121 | case 'Date': |
||
| 122 | $type = 'date'; |
||
| 123 | break; |
||
| 124 | case 'DateTime': |
||
| 125 | $type = 'datetime'; |
||
| 126 | break; |
||
| 127 | case 'Boolean': |
||
| 128 | $type = 'boolean'; |
||
| 129 | break; |
||
| 130 | case 'TextArea': |
||
| 131 | $type = 'text'; |
||
| 132 | break; |
||
| 133 | case 'BigInt': |
||
| 134 | $type = 'bigint'; |
||
| 135 | break; |
||
| 136 | case 'Phone': |
||
| 137 | case 'Auto Number': |
||
| 138 | case 'Text': |
||
| 139 | case 'URL': |
||
| 140 | case 'Email': |
||
| 141 | case 'Website': |
||
| 142 | case 'Pick List': |
||
| 143 | case 'Multiselect Pick List': |
||
| 144 | $type = 'string'; |
||
| 145 | $length = $field['maxlength']; |
||
| 146 | break; |
||
| 147 | case 'Double': |
||
| 148 | case 'Percent': |
||
| 149 | $type = 'float'; |
||
| 150 | break; |
||
| 151 | case 'Integer': |
||
| 152 | $type = 'integer'; |
||
| 153 | break; |
||
| 154 | case 'Currency': |
||
| 155 | case 'Decimal': |
||
| 156 | $type = 'decimal'; |
||
| 157 | break; |
||
| 158 | default: |
||
| 159 | throw new \RuntimeException('Unknown type "'.$field['type'].'"'); |
||
| 160 | } |
||
| 161 | |||
| 162 | $options = []; |
||
| 163 | |||
| 164 | if ($length) { |
||
| 165 | $options['length'] = $length; |
||
| 166 | } |
||
| 167 | |||
| 168 | //$options['notnull'] = $field['req']; |
||
| 169 | $options['notnull'] = false; |
||
| 170 | |||
| 171 | $table->addColumn($columnName, $type, $options); |
||
| 172 | |||
| 173 | if ($index) { |
||
| 174 | $table->addIndex([$columnName]); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | $dbSchema = $this->connection->getSchemaManager()->createSchema(); |
||
| 179 | if ($this->connection->getSchemaManager()->tablesExist($tableName)) { |
||
| 180 | $dbTable = $dbSchema->getTable($tableName); |
||
| 181 | |||
| 182 | $comparator = new \Doctrine\DBAL\Schema\Comparator(); |
||
| 183 | $tableDiff = $comparator->diffTable($dbTable, $table); |
||
| 184 | |||
| 185 | if ($tableDiff !== false) { |
||
| 186 | $this->logger->notice("Changes detected in table structure for ".$tableName.". Applying patch."); |
||
| 187 | $diff = new SchemaDiff(); |
||
| 188 | $diff->fromSchema = $dbSchema; |
||
| 189 | $diff->changedTables[$tableName] = $tableDiff; |
||
| 190 | $statements = $diff->toSaveSql($this->connection->getDatabasePlatform()); |
||
| 191 | foreach ($statements as $sql) { |
||
| 192 | $this->connection->exec($sql); |
||
| 193 | } |
||
| 194 | } else { |
||
| 195 | $this->logger->info("No changes detected in table structure for ".$tableName); |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | $this->logger->notice("Creating new table '$tableName'."); |
||
| 199 | $diff = new SchemaDiff(); |
||
| 200 | $diff->fromSchema = $dbSchema; |
||
| 201 | $diff->newTables[$tableName] = $table; |
||
| 202 | $statements = $diff->toSaveSql($this->connection->getDatabasePlatform()); |
||
| 203 | foreach ($statements as $sql) { |
||
| 204 | $this->connection->exec($sql); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 319 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.