| Conditions | 20 |
| Paths | 246 |
| Total Lines | 98 |
| Code Lines | 73 |
| Lines | 18 |
| Ratio | 18.37 % |
| Changes | 2 | ||
| 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 | switch ($field['type']) { |
||
| 64 | case 'Lookup ID': |
||
| 65 | case 'Lookup': |
||
| 66 | $type = "string"; |
||
| 67 | $length = 100; |
||
| 68 | $index = true; |
||
| 69 | break; |
||
| 70 | case 'OwnerLookup': |
||
| 71 | $type = "string"; |
||
| 72 | $index = true; |
||
| 73 | $length = 25; |
||
| 74 | break; |
||
| 75 | case 'DateTime': |
||
| 76 | $type = "datetime"; |
||
| 77 | break; |
||
| 78 | case 'Date': |
||
| 79 | $type = "date"; |
||
| 80 | break; |
||
| 81 | case 'DateTime': |
||
| 82 | $type = "datetime"; |
||
| 83 | break; |
||
| 84 | case 'Boolean': |
||
| 85 | $type = "boolean"; |
||
| 86 | break; |
||
| 87 | case 'TextArea': |
||
| 88 | $type = "text"; |
||
| 89 | break; |
||
| 90 | case 'Phone': |
||
| 91 | case 'Text': |
||
| 92 | case 'Email': |
||
| 93 | case 'Pick List': |
||
| 94 | $type = "string"; |
||
| 95 | $length = $field['maxlength']; |
||
| 96 | break; |
||
| 97 | default: |
||
| 98 | throw new \RuntimeException('Unknown type "'.$field['type'].'"'); |
||
| 99 | } |
||
| 100 | |||
| 101 | $options = []; |
||
| 102 | |||
| 103 | if ($length) { |
||
| 104 | $options['length'] = $length; |
||
| 105 | } |
||
| 106 | |||
| 107 | //$options['notnull'] = $field['req']; |
||
| 108 | $options['notnull'] = false; |
||
| 109 | |||
| 110 | $table->addColumn($columnName, $type, $options); |
||
| 111 | |||
| 112 | if ($index) { |
||
| 113 | $table->addIndex([ $columnName ]); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | $dbSchema = $this->connection->getSchemaManager()->createSchema(); |
||
| 118 | if ($this->connection->getSchemaManager()->tablesExist($tableName)) { |
||
| 119 | $dbTable = $dbSchema->getTable($tableName); |
||
| 120 | |||
| 121 | $comparator = new \Doctrine\DBAL\Schema\Comparator(); |
||
| 122 | $tableDiff = $comparator->diffTable($dbTable, $table); |
||
| 123 | |||
| 124 | View Code Duplication | if ($tableDiff !== false) { |
|
| 125 | $diff = new SchemaDiff(); |
||
| 126 | $diff->fromSchema = $dbSchema; |
||
| 127 | $diff->changedTables[$tableName] = $tableDiff; |
||
| 128 | $statements = $diff->toSaveSql($this->connection->getDatabasePlatform()); |
||
| 129 | foreach ($statements as $sql) { |
||
| 130 | $this->connection->exec($sql); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | View Code Duplication | } else { |
|
| 134 | $diff = new SchemaDiff(); |
||
| 135 | $diff->fromSchema = $dbSchema; |
||
| 136 | $diff->newTables[$tableName] = $table; |
||
| 137 | $statements = $diff->toSaveSql($this->connection->getDatabasePlatform()); |
||
| 138 | foreach ($statements as $sql) { |
||
| 139 | $this->connection->exec($sql); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | } |
||
| 144 | |||
| 186 |
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.