Conditions | 20 |
Paths | 8192 |
Total Lines | 92 |
Code Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
87 | private function addCorePrimaryKeys(OutputInterface $output) { |
||
88 | $output->writeln('<info>Check primary keys.</info>'); |
||
89 | |||
90 | $schema = new SchemaWrapper($this->connection); |
||
91 | $updated = false; |
||
92 | |||
93 | if ($schema->hasTable('federated_reshares')) { |
||
94 | $table = $schema->getTable('federated_reshares'); |
||
95 | if (!$table->hasPrimaryKey()) { |
||
96 | $output->writeln('<info>Adding primary key to the federated_reshares table, this can take some time...</info>'); |
||
97 | $table->setPrimaryKey(['share_id'], 'federated_res_pk'); |
||
98 | if ($table->hasIndex('share_id_index')) { |
||
99 | $table->dropIndex('share_id_index'); |
||
100 | } |
||
101 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
102 | $updated = true; |
||
103 | $output->writeln('<info>federated_reshares table updated successfully.</info>'); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | if ($schema->hasTable('systemtag_object_mapping')) { |
||
108 | $table = $schema->getTable('systemtag_object_mapping'); |
||
109 | if (!$table->hasPrimaryKey()) { |
||
110 | $output->writeln('<info>Adding primary key to the systemtag_object_mapping table, this can take some time...</info>'); |
||
111 | $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk'); |
||
112 | if ($table->hasIndex('mapping')) { |
||
113 | $table->dropIndex('mapping'); |
||
114 | } |
||
115 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
116 | $updated = true; |
||
117 | $output->writeln('<info>systemtag_object_mapping table updated successfully.</info>'); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | if ($schema->hasTable('comments_read_markers')) { |
||
122 | $table = $schema->getTable('comments_read_markers'); |
||
123 | if (!$table->hasPrimaryKey()) { |
||
124 | $output->writeln('<info>Adding primary key to the comments_read_markers table, this can take some time...</info>'); |
||
125 | $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk'); |
||
126 | if ($table->hasIndex('comments_marker_index')) { |
||
127 | $table->dropIndex('comments_marker_index'); |
||
128 | } |
||
129 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
130 | $updated = true; |
||
131 | $output->writeln('<info>comments_read_markers table updated successfully.</info>'); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | if ($schema->hasTable('collres_resources')) { |
||
136 | $table = $schema->getTable('collres_resources'); |
||
137 | if (!$table->hasPrimaryKey()) { |
||
138 | $output->writeln('<info>Adding primary key to the collres_resources table, this can take some time...</info>'); |
||
139 | $table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk'); |
||
140 | if ($table->hasIndex('collres_unique_res')) { |
||
141 | $table->dropIndex('collres_unique_res'); |
||
142 | } |
||
143 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
144 | $updated = true; |
||
145 | $output->writeln('<info>collres_resources table updated successfully.</info>'); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | if ($schema->hasTable('collres_accesscache')) { |
||
150 | $table = $schema->getTable('collres_accesscache'); |
||
151 | if (!$table->hasPrimaryKey()) { |
||
152 | $output->writeln('<info>Adding primary key to the collres_accesscache table, this can take some time...</info>'); |
||
153 | $table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk'); |
||
154 | if ($table->hasIndex('collres_unique_user')) { |
||
155 | $table->dropIndex('collres_unique_user'); |
||
156 | } |
||
157 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
158 | $updated = true; |
||
159 | $output->writeln('<info>collres_accesscache table updated successfully.</info>'); |
||
160 | } |
||
161 | } |
||
162 | |||
163 | if ($schema->hasTable('filecache_extended')) { |
||
164 | $table = $schema->getTable('filecache_extended'); |
||
165 | if (!$table->hasPrimaryKey()) { |
||
166 | $output->writeln('<info>Adding primary key to the filecache_extended table, this can take some time...</info>'); |
||
167 | $table->setPrimaryKey(['fileid'], 'fce_pk'); |
||
168 | if ($table->hasIndex('fce_fileid_idx')) { |
||
169 | $table->dropIndex('fce_fileid_idx'); |
||
170 | } |
||
171 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
172 | $updated = true; |
||
173 | $output->writeln('<info>filecache_extended table updated successfully.</info>'); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | if (!$updated) { |
||
178 | $output->writeln('<info>Done.</info>'); |
||
179 | } |
||
182 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.