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