| Conditions | 8 |
| Paths | 17 |
| Total Lines | 63 |
| Lines | 21 |
| Ratio | 33.33 % |
| 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 |
||
| 35 | public function Field($properties = array()) |
||
| 36 | { |
||
| 37 | if (! $this->_field_value) { |
||
| 38 | Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js'); |
||
| 39 | Requirements::javascript(THIRDPARTY_DIR .'/jquery-form/jquery.form.js'); |
||
| 40 | Requirements::javascript('pagerater/javascript/jquery.rating.pack.js'); |
||
| 41 | Requirements::javascript('pagerater/javascript/PageRater.js'); |
||
| 42 | if ($this->Config()->get("extra_form_selector")) { |
||
| 43 | Requirements::customScript("PageRater.set_extra_form_selector('".$this->Config()->get("extra_form_selector")."');"); |
||
| 44 | } |
||
| 45 | Requirements::themedCSS('jquery.rating', "pagerater"); |
||
| 46 | $html = ""; |
||
| 47 | |||
| 48 | $name = $this->getName(); |
||
| 49 | $id = $this->id(); |
||
| 50 | for ($i = 1; $i < $this->starOptions + 1; $i++) { |
||
| 51 | if ($i == $this->Value()) { |
||
| 52 | $html .= "<input name='$id' class='$id' type='radio' checked='checked' value='$i' />"; |
||
| 53 | } else { |
||
| 54 | $html .= "<input name='$id' class='$id' type='radio' value='$i' />"; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | $html .= "<input name='$name' type='hidden' id='$id' />"; |
||
| 58 | |||
| 59 | View Code Duplication | if ($this->Config()->get("allow_name")) { |
|
| 60 | $fieldID = $id."_Name"; |
||
| 61 | $nameField = TextField::create($fieldID, _t("PageRaterStarField.NAME_LABEL", "Your Name")); |
||
| 62 | $nameField->addExtraClass("additionalComments"); |
||
| 63 | $html .= $nameField->FieldHolder(); |
||
| 64 | $this->moreFieldsArray[] = $fieldID; |
||
| 65 | } |
||
| 66 | |||
| 67 | View Code Duplication | if ($this->Config()->get("allow_title")) { |
|
| 68 | $fieldID = $id."_Title"; |
||
| 69 | $titleField = TextField::create($fieldID, _t("PageRaterStarField.TITLE_LABEL", "Comment Header")); |
||
| 70 | $titleField->addExtraClass("additionalComments"); |
||
| 71 | $html .= $titleField->FieldHolder(); |
||
| 72 | $this->moreFieldsArray[] = $fieldID; |
||
| 73 | } |
||
| 74 | |||
| 75 | View Code Duplication | if ($this->Config()->get("allow_comments")) { |
|
| 76 | $fieldID = $id."_Comment"; |
||
| 77 | $commentField = TextareaField::create($fieldID, _t("PageRaterStarField.COMMENTS_LABEL", "Any comments you may have")); |
||
| 78 | $commentField->addExtraClass("additionalComments"); |
||
| 79 | $html .= $commentField->FieldHolder(); |
||
| 80 | $this->moreFieldsArray[] = $fieldID; |
||
| 81 | } |
||
| 82 | $moreFieldsAsString = implode("', '", $this->moreFieldsArray); |
||
| 83 | Requirements::customScript(' |
||
| 84 | if(typeof PageRaterVariables === "undefined") { |
||
| 85 | var PageRaterVariables = []; |
||
| 86 | } |
||
| 87 | PageRaterVariables.push( |
||
| 88 | { |
||
| 89 | id: \''.$id.'\', |
||
| 90 | fields: [\''.$moreFieldsAsString.'\'] |
||
| 91 | } |
||
| 92 | ); |
||
| 93 | '); |
||
| 94 | $this->_field_value = $html; |
||
| 95 | } |
||
| 96 | return $this->_field_value; |
||
| 97 | } |
||
| 98 | |||
| 105 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.