| Conditions | 13 |
| Paths | 44 |
| Total Lines | 56 |
| Code Lines | 41 |
| Lines | 30 |
| Ratio | 53.57 % |
| 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 |
||
| 67 | public function render($data, $citationNumber = null) |
||
| 68 | { |
||
| 69 | $lang = (isset($data->language) && $data->language != 'en') ? $data->language : 'en'; |
||
| 70 | |||
| 71 | if (empty($this->variable) || empty($data->{$this->variable})) { |
||
| 72 | return ""; |
||
| 73 | } |
||
| 74 | switch ($this->form) { |
||
| 75 | View Code Duplication | case 'ordinal': |
|
| 76 | $var = $data->{$this->variable}; |
||
| 77 | if (preg_match("/\s*(\d+)\s*[\-\-\&,]\s*(\d+)\s*/", $var, $matches)) { |
||
| 78 | $num1 = self::ordinal($matches[1]); |
||
| 79 | $num2 = self::ordinal($matches[3]); |
||
| 80 | $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); |
||
| 81 | } else { |
||
| 82 | $text = self::ordinal($var); |
||
| 83 | } |
||
| 84 | break; |
||
| 85 | View Code Duplication | case 'long-ordinal': |
|
| 86 | $var = $data->{$this->variable}; |
||
| 87 | if (preg_match("/\s*(\d+)\s*[\-\-\&,]\s*(\d+)\s*/", $var, $matches)) { |
||
| 88 | $num1 = self::longOrdinal($matches[1]); |
||
| 89 | $num2 = self::longOrdinal($matches[3]); |
||
| 90 | $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); |
||
| 91 | } else { |
||
| 92 | $text = self::longOrdinal($var); |
||
| 93 | } |
||
| 94 | break; |
||
| 95 | View Code Duplication | case 'roman': |
|
| 96 | $var = $data->{$this->variable}; |
||
| 97 | if (preg_match("/\s*(\d+)\s*[\-\-\&,]\s*(\d+)\s*/", $var, $matches)) { |
||
| 98 | $num1 = Util\Number::dec2roman($matches[1]); |
||
| 99 | $num2 = Util\Number::dec2roman($matches[3]); |
||
| 100 | $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); |
||
| 101 | } else { |
||
| 102 | $text = Util\Number::dec2roman($var); |
||
| 103 | } |
||
| 104 | break; |
||
| 105 | case 'numeric': |
||
| 106 | default: |
||
| 107 | /* |
||
| 108 | During the extraction, numbers separated by a hyphen are stripped of intervening spaces (“2 - 4” |
||
| 109 | becomes “2-4”). Numbers separated by a comma receive one space after the comma (“2,3” and “2 , 3” |
||
| 110 | become “2, 3”), while numbers separated by an ampersand receive one space before and one after the |
||
| 111 | ampersand (“2&3” becomes “2 & 3”). |
||
| 112 | */ |
||
| 113 | $var = $data->{$this->variable}; |
||
| 114 | if (preg_match("/\s*(\d+)\s*[\-\-\&,]\s*(\d+)\s*/", $var, $matches)) { |
||
| 115 | $text = $this->buildNumberRangeString($matches[1], $matches[3], $matches[2]); |
||
| 116 | } else { |
||
| 117 | $text = Util\Number::dec2roman($var); |
||
| 118 | } |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | return $this->wrapDisplayBlock($this->addAffixes($this->format($this->applyTextCase($text, $lang)))); |
||
| 122 | } |
||
| 123 | |||
| 169 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.