| Conditions | 23 |
| Paths | 4 |
| Total Lines | 223 |
| Code Lines | 129 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 20 | public function __viewIndex() |
||
| 21 | { |
||
| 22 | $canonical_link = '/system/extensions/'; |
||
| 23 | $this->setPageType('table'); |
||
| 24 | $this->setTitle(__('%1$s – %2$s', array(__('Extensions'), __('Symphony')))); |
||
| 25 | $this->addElementToHead(new XMLElement('link', null, array( |
||
| 26 | 'rel' => 'canonical', |
||
| 27 | 'href' => SYMPHONY_URL . $canonical_link, |
||
| 28 | ))); |
||
| 29 | $this->appendSubheading(__('Extensions')); |
||
| 30 | |||
| 31 | $this->Form->setAttribute('action', SYMPHONY_URL . $canonical_link); |
||
| 32 | |||
| 33 | Sortable::initialize($this, $extensions, $sort, $order); |
||
| 34 | |||
| 35 | $columns = array( |
||
| 36 | array( |
||
| 37 | 'label' => __('Name'), |
||
| 38 | 'sortable' => true, |
||
| 39 | 'handle' => 'name' |
||
| 40 | ), |
||
| 41 | array( |
||
| 42 | 'label' => __('Version'), |
||
| 43 | 'sortable' => false, |
||
| 44 | ), |
||
| 45 | array( |
||
| 46 | 'label' => __('Status'), |
||
| 47 | 'sortable' => false, |
||
| 48 | ), |
||
| 49 | array( |
||
| 50 | 'label' => __('Links'), |
||
| 51 | 'sortable' => false, |
||
| 52 | 'handle' => 'links' |
||
| 53 | ), |
||
| 54 | array( |
||
| 55 | 'label' => __('Authors'), |
||
| 56 | 'sortable' => true, |
||
| 57 | 'handle' => 'author' |
||
| 58 | ) |
||
| 59 | ); |
||
| 60 | |||
| 61 | $aTableHead = Sortable::buildTableHeaders( |
||
| 62 | $columns, |
||
| 63 | $sort, |
||
| 64 | $order, |
||
| 65 | (isset($_REQUEST['filter']) ? '&filter=' . $_REQUEST['filter'] : '') |
||
| 66 | ); |
||
| 67 | |||
| 68 | $aTableBody = array(); |
||
| 69 | |||
| 70 | if (!is_array($extensions) || empty($extensions)) { |
||
| 71 | $aTableBody = array( |
||
| 72 | Widget::TableRow(array( |
||
| 73 | Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead)) |
||
| 74 | ), 'odd') |
||
| 75 | ); |
||
| 76 | } else { |
||
| 77 | foreach ($extensions as $name => $about) { |
||
| 78 | // Name |
||
| 79 | $td1 = Widget::TableData($about['name']); |
||
| 80 | $td1->appendChild(Widget::Label(__('Select %s Extension', array($about['name'])), null, 'accessible', null, array( |
||
| 81 | 'for' => 'extension-' . $name |
||
| 82 | ))); |
||
| 83 | $td1->appendChild(Widget::Input('items['.$name.']', 'on', 'checkbox', array( |
||
| 84 | 'id' => 'extension-' . $name |
||
| 85 | ))); |
||
| 86 | |||
| 87 | // Version |
||
| 88 | $installed_version = Symphony::ExtensionManager()->fetchInstalledVersion($name); |
||
| 89 | |||
| 90 | if (in_array(Extension::EXTENSION_NOT_INSTALLED, $about['status'])) { |
||
| 91 | $td2 = Widget::TableData($about['version']); |
||
| 92 | } elseif (in_array(Extension::EXTENSION_REQUIRES_UPDATE, $about['status'])) { |
||
| 93 | $td2 = Widget::TableData($installed_version . '<i> → ' . $about['version'] . '</i>'); |
||
| 94 | } else { |
||
| 95 | $td2 = Widget::TableData($installed_version); |
||
| 96 | } |
||
| 97 | |||
| 98 | // Status |
||
| 99 | $trClasses = array(); |
||
| 100 | $trStatus = ''; |
||
| 101 | $tdMessage = __('Status unavailable'); |
||
| 102 | |||
| 103 | if (in_array(Extension::EXTENSION_NOT_INSTALLED, $about['status'])) { |
||
| 104 | $tdMessage = __('Not installed'); |
||
| 105 | $trClasses[] = 'inactive'; |
||
| 106 | $trClasses[] = 'extension-can-install'; |
||
| 107 | } |
||
| 108 | |||
| 109 | if (in_array(Extension::EXTENSION_DISABLED, $about['status'])) { |
||
| 110 | $tdMessage = __('Disabled'); |
||
| 111 | $trStatus = 'status-notice'; |
||
| 112 | } |
||
| 113 | |||
| 114 | if (in_array(Extension::EXTENSION_ENABLED, $about['status'])) { |
||
| 115 | $tdMessage = __('Enabled'); |
||
| 116 | } |
||
| 117 | |||
| 118 | if (in_array(Extension::EXTENSION_REQUIRES_UPDATE, $about['status'])) { |
||
| 119 | $tdMessage = __('Update available'); |
||
| 120 | $trClasses[] = 'extension-can-update'; |
||
| 121 | $trStatus = 'status-ok'; |
||
| 122 | } |
||
| 123 | |||
| 124 | if (in_array(Extension::EXTENSION_NOT_COMPATIBLE, $about['status'])) { |
||
| 125 | $tdMessage .= ', ' . __('requires Symphony %s', array($about['required_version'])); |
||
| 126 | $trStatus = 'status-error'; |
||
| 127 | } |
||
| 128 | |||
| 129 | $trClasses[] = $trStatus; |
||
| 130 | $td3 = Widget::TableData($tdMessage); |
||
| 131 | |||
| 132 | // Links |
||
| 133 | $tdLinks = array(); |
||
| 134 | |||
| 135 | if ($about['github'] != '') { |
||
| 136 | $tdLinks['github'] = Widget::Anchor(__('GitHub'), General::validateURL($about['github']))->generate(); |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($about['discuss'] != '') { |
||
| 140 | $tdLinks['discuss'] = Widget::Anchor(__('Discuss'), General::validateURL($about['discuss']))->generate(); |
||
| 141 | // Update links to point to our 'new' domain, RE: #1995 |
||
| 142 | $tdLinks['discuss'] = str_replace('symphony-cms.com', 'getsymphony.com', $tdLinks['discuss']); |
||
| 143 | } |
||
| 144 | |||
| 145 | if ($about['homepage'] != '') { |
||
| 146 | $tdLinks['homepage'] = Widget::Anchor(__('Homepage'), General::validateURL($about['homepage']))->generate(); |
||
| 147 | } |
||
| 148 | |||
| 149 | if ($about['wiki'] != '') { |
||
| 150 | $tdLinks['wiki'] = Widget::Anchor(__('Wiki'), General::validateURL($about['wiki']))->generate(); |
||
| 151 | } |
||
| 152 | |||
| 153 | if ($about['issues'] != '') { |
||
| 154 | $tdLinks['issues'] = Widget::Anchor(__('Issues'), General::validateURL($about['issues']))->generate(); |
||
| 155 | } |
||
| 156 | |||
| 157 | $td4 = Widget::TableData($tdLinks); |
||
| 158 | |||
| 159 | // Authors |
||
| 160 | $tdAuthors = array(); |
||
| 161 | |||
| 162 | if (!is_array($about['author'])) { |
||
| 163 | $about['author'] = array($about['author']); |
||
| 164 | } |
||
| 165 | |||
| 166 | foreach ($about['author'] as $author) { |
||
| 167 | if (isset($author['website'])) { |
||
| 168 | $tdAuthors[] = Widget::Anchor($author['name'], General::validateURL($author['website']))->generate(); |
||
| 169 | } elseif (isset($author['github'])) { |
||
| 170 | $tdAuthors[] = Widget::Anchor($author['name'], General::validateURL('https://github.com/' . $author['github']))->generate(); |
||
| 171 | } elseif (isset($author['email'])) { |
||
| 172 | $tdAuthors[] = Widget::Anchor($author['name'], 'mailto:' . $author['email'])->generate(); |
||
| 173 | } else { |
||
| 174 | $tdAuthors[] = $author['name']; |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | $td5 = Widget::TableData($tdAuthors); |
||
| 179 | |||
| 180 | // Create the table row |
||
| 181 | $tr = Widget::TableRow(array($td1, $td2, $td3, $td4, $td5), implode(' ', $trClasses)); |
||
| 182 | |||
| 183 | // Add some attributes about the extension |
||
| 184 | $tr->setAttribute('data-handle', $name); |
||
| 185 | $tr->setAttribute('data-installed-version', $installed_version); |
||
| 186 | $tr->setAttribute('data-meta-version', $about['version']); |
||
| 187 | |||
| 188 | // Add a row to the body array, assigning each cell to the row |
||
| 189 | $aTableBody[] = $tr; |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | $table = Widget::Table( |
||
| 194 | Widget::TableHead($aTableHead), |
||
| 195 | null, |
||
| 196 | Widget::TableBody($aTableBody), |
||
| 197 | 'selectable', |
||
| 198 | null, |
||
| 199 | array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive') |
||
| 200 | ); |
||
| 201 | |||
| 202 | $this->Form->appendChild($table); |
||
| 203 | |||
| 204 | $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array( |
||
| 205 | 'id' => 'version' |
||
| 206 | )); |
||
| 207 | |||
| 208 | $this->Form->appendChild($version); |
||
| 209 | |||
| 210 | $tableActions = new XMLElement('div'); |
||
| 211 | $tableActions->setAttribute('class', 'actions'); |
||
| 212 | |||
| 213 | $options = array( |
||
| 214 | array(null, false, __('With Selected...')), |
||
| 215 | array('enable', false, __('Enable')), |
||
| 216 | array('disable', false, __('Disable')), |
||
| 217 | array('uninstall', false, __('Uninstall'), 'confirm', null, array( |
||
| 218 | 'data-message' => __('Are you sure you want to uninstall the selected extensions?') |
||
| 219 | )) |
||
| 220 | ); |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Allows an extension to modify the existing options for this page's |
||
| 224 | * With Selected menu. If the `$options` parameter is an empty array, |
||
| 225 | * the 'With Selected' menu will not be rendered. |
||
| 226 | * |
||
| 227 | * @delegate AddCustomActions |
||
| 228 | * @since Symphony 2.3.2 |
||
| 229 | * @param string $context |
||
| 230 | * '/system/extensions/' |
||
| 231 | * @param array $options |
||
| 232 | * An array of arrays, where each child array represents an option |
||
| 233 | * in the With Selected menu. Options should follow the same format |
||
| 234 | * expected by `Widget::__SelectBuildOption`. Passed by reference. |
||
| 235 | */ |
||
| 236 | Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/system/extensions/', array( |
||
| 237 | 'options' => &$options |
||
| 238 | )); |
||
| 239 | |||
| 240 | if (!empty($options)) { |
||
| 241 | $tableActions->appendChild(Widget::Apply($options)); |
||
| 242 | $this->Form->appendChild($tableActions); |
||
| 243 | } |
||
| 333 |
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.