Conditions | 4 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 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 |
||
40 | public function getAdDetails($url) |
||
41 | { |
||
42 | $client = new Client(); |
||
43 | |||
44 | // get ads |
||
45 | $request = new Request('GET', $url); |
||
46 | $promise = $client->sendAsync($request)->then(function ($response) { |
||
47 | $html = $response->getBody()->getContents(); |
||
48 | |||
49 | $dom = HtmlDomParser::str_get_html($html); |
||
50 | |||
51 | // breadcrumbs |
||
52 | foreach ($dom->find('div.breadcrumbs a') as $a) { |
||
53 | $this->ad['categories'][] = [ |
||
54 | 'href' => $a->href, |
||
55 | 'name' => $a->plaintext, |
||
56 | ]; |
||
57 | } |
||
58 | |||
59 | // title |
||
60 | $this->ad['title'] = $dom->find('div.title-container h1')->plaintext; |
||
61 | |||
62 | // price |
||
63 | $this->ad['price'] = [ |
||
64 | 'value' => $dom->find('div.price-container div.price span.price-val', 0)->plaintext, |
||
65 | 'currency' => $dom->find('div.price-container div.price span.price-cur', 0)->plaintext, |
||
66 | ]; |
||
67 | |||
68 | // properties |
||
69 | foreach ($dom->find('table.properties tr.property') as $property) { |
||
70 | $this->ad['properties'][] = [ |
||
71 | 'name' => $property->find('td.property-name', 0)->innertext, |
||
72 | 'value' => $property->find('td.property-value', 0)->innertext, |
||
73 | ]; |
||
74 | } |
||
75 | |||
76 | // description |
||
77 | $this->ad['description'] = $this->br2nl($dom->find('div.lot-text p', 0)->innertext); |
||
78 | |||
79 | // author |
||
80 | $this->ad['author'] = [ |
||
81 | 'name' => $dom->find('div.author div.name', 0)->innertext, |
||
82 | 'phone' => $dom->find('div.author a.phone', 0)->innertext, |
||
83 | ]; |
||
84 | |||
85 | // photos |
||
86 | foreach ($dom->find('div.photos div.l-center div.short-view a') as $photo) { |
||
87 | $this->ad['photos'][] = [ |
||
88 | 'thumb' => $photo->find('img', 0)->src, |
||
89 | 'large' => $photo->href, |
||
90 | ]; |
||
91 | } |
||
92 | }); |
||
93 | |||
94 | $promise->wait(); |
||
95 | } |
||
105 |