| Conditions | 9 |
| Paths | 10 |
| Total Lines | 68 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 96 | private function get($database, $field_id, $search, $max) |
||
| 97 | { |
||
| 98 | // Get entries |
||
| 99 | if (!empty($search)) { |
||
| 100 | |||
| 101 | // Get columns |
||
| 102 | $columns = Symphony::Database()->fetchCol('column_name', |
||
| 103 | sprintf( |
||
| 104 | "SELECT column_name |
||
| 105 | FROM information_schema.columns |
||
| 106 | WHERE table_schema = '%s' |
||
| 107 | AND table_name = 'tbl_entries_data_%d' |
||
| 108 | AND column_name != 'id' |
||
| 109 | AND column_name != 'entry_id';", |
||
| 110 | $database, |
||
| 111 | $field_id |
||
| 112 | ) |
||
| 113 | ); |
||
| 114 | |||
| 115 | // Build where clauses |
||
| 116 | $where = array(); |
||
| 117 | foreach ($columns as $column) { |
||
| 118 | $where[] = "`$column` LIKE '%$search%'"; |
||
| 119 | } |
||
| 120 | |||
| 121 | // Build query |
||
| 122 | $query = sprintf( |
||
| 123 | "SELECT * from tbl_entries_data_%d WHERE %s%s;", |
||
| 124 | $field_id, |
||
| 125 | implode($where, " OR "), |
||
| 126 | $max |
||
| 127 | ); |
||
| 128 | } else { |
||
| 129 | $query = sprintf( |
||
| 130 | "SELECT * from tbl_entries_data_%d%s;", |
||
| 131 | $field_id, |
||
| 132 | $max |
||
| 133 | ); |
||
| 134 | } |
||
| 135 | |||
| 136 | // Fetch field values |
||
| 137 | $data = Symphony::Database()->fetch($query); |
||
| 138 | |||
| 139 | if (!empty($data)) { |
||
| 140 | $field = FieldManager::fetch($field_id); |
||
| 141 | $parent_section = SectionManager::fetch($field->get('parent_section')); |
||
| 142 | $parent_section_handle = $parent_section->get('handle'); |
||
| 143 | |||
| 144 | foreach ($data as $field_data) { |
||
| 145 | $entry_id = $field_data['entry_id']; |
||
| 146 | |||
| 147 | if ($field instanceof ExportableField && in_array(ExportableField::UNFORMATTED, $field->getExportModes())) { |
||
| 148 | |||
| 149 | // Get unformatted value |
||
| 150 | $value = $field->prepareExportValue($field_data, ExportableField::UNFORMATTED, $entry_id); |
||
| 151 | } elseif ($field instanceof ExportableField && in_array(ExportableField::VALUE, $field->getExportModes())) { |
||
| 152 | |||
| 153 | // Get formatted value |
||
| 154 | $value = $field->prepareExportValue($field_data, ExportableField::VALUE, $entry_id); |
||
| 155 | } else { |
||
| 156 | |||
| 157 | // Get value from parameter pool |
||
| 158 | $value = $field->getParameterPoolValue($field_data, $entry_id); |
||
| 159 | } |
||
| 160 | |||
| 161 | $this->_Result['entries'][$entry_id]['value'] = $value; |
||
| 162 | $this->_Result['entries'][$entry_id]['section'] = $parent_section_handle; |
||
| 163 | $this->_Result['entries'][$entry_id]['link'] = APPLICATION_URL . '/publish/' . $parent_section_handle . '/edit/' . $entry_id . '/'; |
||
| 164 | } |
||
| 168 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider.