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