| Conditions | 7 |
| Paths | 4 |
| Total Lines | 68 |
| Code Lines | 31 |
| 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 |
||
| 51 | public function createJSON() |
||
| 52 | { |
||
| 53 | SSViewer::set_source_file_comments(false); |
||
| 54 | $json = ' |
||
| 55 | { |
||
| 56 | "timeline": |
||
| 57 | { |
||
| 58 | "headline":'.$this->html2json($this->TimeLineHeader).', |
||
| 59 | "type":"default", |
||
| 60 | "text": '.$this->html2json($this->TimeLineIntro).', |
||
| 61 | "date": ['; |
||
| 62 | //'.$this->html2json($this->TimeLineIntro).'';// |
||
| 63 | //"asset": { |
||
| 64 | // "media":"http://yourdomain_or_socialmedialink_goes_here.jpg", |
||
| 65 | // "credit":"Credit Name Goes Here", |
||
| 66 | // "caption":"Caption text goes here" |
||
| 67 | //}, |
||
| 68 | |||
| 69 | $data = $this->WebPortfolioItems(); |
||
| 70 | if ($data && $data->count()) { |
||
| 71 | $dayExistsArray = array(); |
||
| 72 | foreach ($data as $site) { |
||
| 73 | if ($site->StartDate) { |
||
| 74 | $startDateRaw = $site->StartDate; |
||
| 75 | } else { |
||
| 76 | $startDateRaw = $this->Created; |
||
| 77 | } |
||
| 78 | $startDateArray = explode("-", $startDateRaw); |
||
| 79 | $startDate = intval($startDateArray[0]). ",".intval($startDateArray[1]). ",".intval($startDateArray[2]); |
||
| 80 | $headLine = $this->html2json($site->getHeadLine()); |
||
| 81 | $text = $this->html2json($site->renderWith("WebPortfolioPageOneItemTimeline")); // // |
||
| 82 | $json .= ' |
||
| 83 | { |
||
| 84 | "startDate":"'.$startDate.'", |
||
| 85 | "headline": '.$headLine.', |
||
| 86 | "text": '.$text.' |
||
| 87 | } |
||
| 88 | '; |
||
| 89 | if (!$site->Last()) { |
||
| 90 | $json .= ","; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | /* |
||
| 95 | "era": [ |
||
| 96 | { |
||
| 97 | "startDate":"2011,12,10", |
||
| 98 | "endDate":"2011,12,11", |
||
| 99 | "headline":"Headline Goes Here", |
||
| 100 | "text":"<p>Body text goes here, some HTML is OK</p>", |
||
| 101 | "tag":"This is Optional" |
||
| 102 | } |
||
| 103 | |||
| 104 | ] |
||
| 105 | */ |
||
| 106 | $json .=' |
||
| 107 | ] |
||
| 108 | } |
||
| 109 | }'; |
||
| 110 | if ($json) { |
||
| 111 | $this->JSON = $json; |
||
| 112 | $this->writeToStage('Stage'); |
||
| 113 | $this->Publish('Stage', 'Live'); |
||
| 114 | $this->Status = "Published"; |
||
| 115 | $this->flushCache(); |
||
| 116 | } |
||
| 117 | return $json; |
||
| 118 | } |
||
| 119 | |||
| 167 |
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.