| Conditions | 31 |
| Paths | 374 |
| Total Lines | 110 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 69 | public function synchronizeDbModel(AbstractZohoDao $dao, $twoWaysSync, $skipCreateTrigger = false) |
||
| 70 | { |
||
| 71 | if ($twoWaysSync === true) { |
||
| 72 | $this->localChangesTracker->createTrackingTables(); |
||
| 73 | } |
||
| 74 | |||
| 75 | $tableName = ZohoDatabaseHelper::getTableName($dao, $this->prefix); |
||
| 76 | $this->logger->info('Synchronizing DB Model for '.$tableName); |
||
| 77 | |||
| 78 | $schema = new Schema(); |
||
| 79 | $table = $schema->createTable($tableName); |
||
| 80 | |||
| 81 | $flatFields = ZohoDatabaseHelper::getFlatFields($dao->getFields()); |
||
|
|
|||
| 82 | $table->addColumn('uid', 'integer', ['autoincrement' => true]); |
||
| 83 | $table->addColumn('id', 'string', ['length' => 100]); |
||
| 84 | $table->addUniqueIndex(['id']); |
||
| 85 | $table->setPrimaryKey(['uid']); |
||
| 86 | |||
| 87 | foreach ($flatFields as $field) { |
||
| 88 | $columnName = $field['name']; |
||
| 89 | |||
| 90 | $length = null; |
||
| 91 | $index = false; |
||
| 92 | |||
| 93 | // Note: full list of types available here: https://www.zoho.com/crm/help/customization/custom-fields.html |
||
| 94 | switch ($field['type']) { |
||
| 95 | case 'Lookup ID': |
||
| 96 | case 'Lookup': |
||
| 97 | $type = 'string'; |
||
| 98 | $length = 100; |
||
| 99 | $index = true; |
||
| 100 | break; |
||
| 101 | case 'OwnerLookup': |
||
| 102 | $type = 'string'; |
||
| 103 | $index = true; |
||
| 104 | $length = 25; |
||
| 105 | break; |
||
| 106 | case 'Formula': |
||
| 107 | // Note: a Formula can return any type, but we have no way to know which type it returns... |
||
| 108 | $type = 'string'; |
||
| 109 | $length = 100; |
||
| 110 | break; |
||
| 111 | case 'DateTime': |
||
| 112 | $type = 'datetime'; |
||
| 113 | break; |
||
| 114 | case 'Date': |
||
| 115 | $type = 'date'; |
||
| 116 | break; |
||
| 117 | case 'DateTime': |
||
| 118 | $type = 'datetime'; |
||
| 119 | break; |
||
| 120 | case 'Boolean': |
||
| 121 | $type = 'boolean'; |
||
| 122 | break; |
||
| 123 | case 'TextArea': |
||
| 124 | $type = 'text'; |
||
| 125 | break; |
||
| 126 | case 'BigInt': |
||
| 127 | $type = 'bigint'; |
||
| 128 | break; |
||
| 129 | case 'Phone': |
||
| 130 | case 'Auto Number': |
||
| 131 | case 'Text': |
||
| 132 | case 'URL': |
||
| 133 | case 'Email': |
||
| 134 | case 'Website': |
||
| 135 | case 'Pick List': |
||
| 136 | case 'Multiselect Pick List': |
||
| 137 | $type = 'string'; |
||
| 138 | $length = $field['maxlength']; |
||
| 139 | break; |
||
| 140 | case 'Double': |
||
| 141 | case 'Percent': |
||
| 142 | $type = 'float'; |
||
| 143 | break; |
||
| 144 | case 'Integer': |
||
| 145 | $type = 'integer'; |
||
| 146 | break; |
||
| 147 | case 'Currency': |
||
| 148 | case 'Decimal': |
||
| 149 | $type = 'decimal'; |
||
| 150 | break; |
||
| 151 | default: |
||
| 152 | throw new \RuntimeException('Unknown type "'.$field['type'].'"'); |
||
| 153 | } |
||
| 154 | |||
| 155 | $options = []; |
||
| 156 | |||
| 157 | if ($length) { |
||
| 158 | $options['length'] = $length; |
||
| 159 | } |
||
| 160 | |||
| 161 | //$options['notnull'] = $field['req']; |
||
| 162 | $options['notnull'] = false; |
||
| 163 | |||
| 164 | $table->addColumn($columnName, $type, $options); |
||
| 165 | |||
| 166 | if ($index) { |
||
| 167 | $table->addIndex([$columnName]); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | $dbalTableDiffService = new DbalTableDiffService($this->connection, $this->logger); |
||
| 172 | $hasChanges = $dbalTableDiffService->createOrUpdateTable($table); |
||
| 173 | if ($twoWaysSync && ($hasChanges || !$skipCreateTrigger)) { |
||
| 174 | $this->localChangesTracker->createInsertTrigger($table); |
||
| 175 | $this->localChangesTracker->createDeleteTrigger($table); |
||
| 176 | $this->localChangesTracker->createUpdateTrigger($table); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | } |
||
| 180 |
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.