| Conditions | 4 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 39 |
| 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 |
||
| 46 | public function parseEvents($url) |
||
| 47 | { |
||
| 48 | $crawler = $this->client->request('GET', $url); |
||
| 49 | |||
| 50 | $events = []; |
||
| 51 | |||
| 52 | $crawler->filter('script')->each(function (Crawler $node) use (&$events, $url) { |
||
| 53 | $text = $node->text(); |
||
| 54 | |||
| 55 | $containers = [ |
||
| 56 | "#events-open-for-applicationcontainer", |
||
| 57 | "#events-in-progresscontainer", |
||
| 58 | "#past-eventscontainer" |
||
| 59 | ]; |
||
| 60 | |||
| 61 | foreach ($containers as $container) { |
||
| 62 | |||
| 63 | if (strpos($text, $container)) { |
||
| 64 | |||
| 65 | $items = explode("'items':", $text); |
||
| 66 | $items = $items[1]; |
||
| 67 | $items = trim($items); |
||
| 68 | |||
| 69 | $items = preg_replace('/\s+/', ' ', $items); |
||
| 70 | $items = str_replace("'", '"', $items); |
||
| 71 | $items = str_replace("], }", "] }", $items); |
||
| 72 | $items = str_replace("}, ]", "} ]", $items); |
||
| 73 | $items = str_replace("\", ]", "\" ]", $items); |
||
| 74 | $items = str_replace("\", }", "\" }", $items); |
||
| 75 | |||
| 76 | $length = strlen($items); |
||
| 77 | |||
| 78 | $items = substr($items, 0, $length-6); |
||
| 79 | $items = json_decode($items, true); |
||
| 80 | |||
| 81 | foreach ($items as $item) { |
||
| 82 | |||
| 83 | $event = []; |
||
| 84 | |||
| 85 | $description = $item["description"]; |
||
| 86 | $description = str_replace("\n", "", $description); |
||
| 87 | $description = str_replace("\r", "", $description); |
||
| 88 | |||
| 89 | $event['title'] = $item['title']; |
||
| 90 | $event['organizer'] = trim(explode("by", explode("<hr>", $description)[0])[1]); |
||
| 91 | $event['start'] = explode("</date>", explode("<date>", $description)[1])[0]; |
||
| 92 | $event['end'] = explode("</date>", explode("till <date>", $description)[1])[0]; |
||
| 93 | $event['deadline'] = trim(explode("</date>", explode("Application Deadline <date>", $description)[1])[0]); |
||
| 94 | $event['image'] = $item['large'][0]; |
||
| 95 | $event['url'] = $item['button_list'][0]['url']; |
||
| 96 | $parts = explode("<hr>", $description); |
||
| 97 | $event['details'] = $parts[count($parts) - 1]; |
||
| 98 | |||
| 99 | $events[] = $event; |
||
| 100 | |||
| 101 | } |
||
| 102 | |||
| 103 | } |
||
| 104 | |||
| 105 | } |
||
| 106 | |||
| 107 | }); |
||
| 108 | |||
| 109 | return $events; |
||
| 110 | } |
||
| 111 | } |
||
| 112 |