| Conditions | 15 |
| Paths | 6 |
| Total Lines | 63 |
| Lines | 40 |
| Ratio | 63.49 % |
| 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 |
||
| 31 | public function display($cachable = false, $urlparams = false) |
||
| 32 | { |
||
| 33 | require_once JPATH_COMPONENT . '/helpers/localise.php'; |
||
| 34 | $app = JFactory::getApplication('administrator'); |
||
|
|
|||
| 35 | |||
| 36 | $vName = $this->input->get('view', 'languages'); |
||
| 37 | $layout = $this->input->get('layout', 'default'); |
||
| 38 | $id = $this->input->getInt('id'); |
||
| 39 | |||
| 40 | if ($vName == 'translations') |
||
| 41 | { |
||
| 42 | $view = $this->getView('translations', 'html'); |
||
| 43 | $packages = $this->getModel('Packages', 'LocaliseModel', array('ignore_request' => true)); |
||
| 44 | $view->setModel($packages); |
||
| 45 | } |
||
| 46 | // Check for edit form. |
||
| 47 | View Code Duplication | elseif ($vName == 'language' && $layout == 'edit' |
|
| 48 | && !$this->checkEditId('com_localise.edit.language', $id)) |
||
| 49 | { |
||
| 50 | // Somehow the person just went to the form - we don't allow that. |
||
| 51 | $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); |
||
| 52 | $this->setMessage($this->getError(), 'error'); |
||
| 53 | $this->setRedirect(JRoute::_('index.php?option=com_localise&view=languages', false)); |
||
| 54 | |||
| 55 | return false; |
||
| 56 | } |
||
| 57 | View Code Duplication | elseif ($vName == 'translation' && ($layout == 'edit' || $layout == 'raw') |
|
| 58 | && !$this->checkEditId('com_localise.edit.translation', $id)) |
||
| 59 | { |
||
| 60 | // Somehow the person just went to the form - we don't allow that. |
||
| 61 | $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); |
||
| 62 | $this->setMessage($this->getError(), 'error'); |
||
| 63 | $this->setRedirect(JRoute::_('index.php?option=com_localise&view=translations', false)); |
||
| 64 | |||
| 65 | return false; |
||
| 66 | } |
||
| 67 | View Code Duplication | elseif ($vName == 'packagefile' && $layout == 'edit' |
|
| 68 | && !$this->checkEditId('com_localise.edit.packagefile', $id)) |
||
| 69 | { |
||
| 70 | // Somehow the person just went to the form - we don't allow that. |
||
| 71 | $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); |
||
| 72 | $this->setMessage($this->getError(), 'error'); |
||
| 73 | $this->setRedirect(JRoute::_('index.php?option=com_localise&view=packages', false)); |
||
| 74 | |||
| 75 | return false; |
||
| 76 | } |
||
| 77 | View Code Duplication | elseif ($vName == 'package' && $layout == 'edit' |
|
| 78 | && !$this->checkEditId('com_localise.edit.package', $id)) |
||
| 79 | { |
||
| 80 | // Somehow the person just went to the form - we don't allow that. |
||
| 81 | $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); |
||
| 82 | $this->setMessage($this->getError(), 'error'); |
||
| 83 | $this->setRedirect(JRoute::_('index.php?option=com_localise&view=packages', false)); |
||
| 84 | |||
| 85 | return false; |
||
| 86 | } |
||
| 87 | else |
||
| 88 | { |
||
| 89 | $this->input->set('view', $vName); |
||
| 90 | } |
||
| 91 | |||
| 92 | parent::display($cachable, $urlparams); |
||
| 93 | } |
||
| 94 | } |
||
| 95 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.