| Conditions | 30 |
| Paths | 446 |
| Total Lines | 117 |
| Code Lines | 91 |
| Lines | 18 |
| Ratio | 15.38 % |
| Changes | 4 | ||
| 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 |
||
| 46 | private function synchronizeDbModel(AbstractZohoDao $dao) { |
||
| 47 | $tableName = $this->prefix.$dao->getModule(); |
||
|
|
|||
| 48 | |||
| 49 | $schema = new Schema(); |
||
| 50 | $table = $schema->createTable($tableName); |
||
| 51 | |||
| 52 | $flatFields = $this->getFlatFields($dao->getFields()); |
||
| 53 | |||
| 54 | $table->addColumn("id", "string", ['length'=>100]); |
||
| 55 | $table->setPrimaryKey(['id']); |
||
| 56 | |||
| 57 | foreach ($flatFields as $field) { |
||
| 58 | $columnName = $field['name']; |
||
| 59 | |||
| 60 | $length = null; |
||
| 61 | $index = false; |
||
| 62 | |||
| 63 | // Note: full list of types available here: https://www.zoho.com/crm/help/customization/custom-fields.html |
||
| 64 | switch ($field['type']) { |
||
| 65 | case 'Lookup ID': |
||
| 66 | case 'Lookup': |
||
| 67 | $type = "string"; |
||
| 68 | $length = 100; |
||
| 69 | $index = true; |
||
| 70 | break; |
||
| 71 | case 'OwnerLookup': |
||
| 72 | $type = "string"; |
||
| 73 | $index = true; |
||
| 74 | $length = 25; |
||
| 75 | break; |
||
| 76 | case 'DateTime': |
||
| 77 | $type = "datetime"; |
||
| 78 | break; |
||
| 79 | case 'Date': |
||
| 80 | $type = "date"; |
||
| 81 | break; |
||
| 82 | case 'DateTime': |
||
| 83 | $type = "datetime"; |
||
| 84 | break; |
||
| 85 | case 'Boolean': |
||
| 86 | $type = "boolean"; |
||
| 87 | break; |
||
| 88 | case 'TextArea': |
||
| 89 | $type = "text"; |
||
| 90 | break; |
||
| 91 | case 'BigInt': |
||
| 92 | $type = "bigint"; |
||
| 93 | break; |
||
| 94 | case 'Phone': |
||
| 95 | case 'Auto Number': |
||
| 96 | case 'Text': |
||
| 97 | case 'URL': |
||
| 98 | case 'Email': |
||
| 99 | case 'Website': |
||
| 100 | case 'Pick List': |
||
| 101 | case 'Multiselect Pick List': |
||
| 102 | $type = "string"; |
||
| 103 | $length = $field['maxlength']; |
||
| 104 | break; |
||
| 105 | case 'Double': |
||
| 106 | case 'Percent': |
||
| 107 | $type = "float"; |
||
| 108 | break; |
||
| 109 | case 'Integer': |
||
| 110 | $type = "integer"; |
||
| 111 | break; |
||
| 112 | case 'Currency': |
||
| 113 | case 'Decimal': |
||
| 114 | $type = "decimal"; |
||
| 115 | break; |
||
| 116 | default: |
||
| 117 | throw new \RuntimeException('Unknown type "'.$field['type'].'"'); |
||
| 118 | } |
||
| 119 | |||
| 120 | $options = []; |
||
| 121 | |||
| 122 | if ($length) { |
||
| 123 | $options['length'] = $length; |
||
| 124 | } |
||
| 125 | |||
| 126 | //$options['notnull'] = $field['req']; |
||
| 127 | $options['notnull'] = false; |
||
| 128 | |||
| 129 | $table->addColumn($columnName, $type, $options); |
||
| 130 | |||
| 131 | if ($index) { |
||
| 132 | $table->addIndex([ $columnName ]); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | $dbSchema = $this->connection->getSchemaManager()->createSchema(); |
||
| 137 | if ($this->connection->getSchemaManager()->tablesExist($tableName)) { |
||
| 138 | $dbTable = $dbSchema->getTable($tableName); |
||
| 139 | |||
| 140 | $comparator = new \Doctrine\DBAL\Schema\Comparator(); |
||
| 141 | $tableDiff = $comparator->diffTable($dbTable, $table); |
||
| 142 | |||
| 143 | View Code Duplication | if ($tableDiff !== false) { |
|
| 144 | $diff = new SchemaDiff(); |
||
| 145 | $diff->fromSchema = $dbSchema; |
||
| 146 | $diff->changedTables[$tableName] = $tableDiff; |
||
| 147 | $statements = $diff->toSaveSql($this->connection->getDatabasePlatform()); |
||
| 148 | foreach ($statements as $sql) { |
||
| 149 | $this->connection->exec($sql); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | View Code Duplication | } else { |
|
| 153 | $diff = new SchemaDiff(); |
||
| 154 | $diff->fromSchema = $dbSchema; |
||
| 155 | $diff->newTables[$tableName] = $table; |
||
| 156 | $statements = $diff->toSaveSql($this->connection->getDatabasePlatform()); |
||
| 157 | foreach ($statements as $sql) { |
||
| 158 | $this->connection->exec($sql); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | } |
||
| 163 | |||
| 219 |
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.