| Conditions | 5 |
| Paths | 12 |
| Total Lines | 81 |
| Code Lines | 57 |
| 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 |
||
| 149 | public function all($type, array $attr, $locale='en') |
||
| 150 | { |
||
| 151 | $res = new \StdClass(); |
||
| 152 | |||
| 153 | $brand = isset($attr['brand']) ? $attr['brand'] : null; |
||
| 154 | |||
| 155 | $res->title = $this->title( |
||
| 156 | $type, |
||
| 157 | $attr, |
||
| 158 | $locale |
||
| 159 | ); |
||
| 160 | |||
| 161 | $res->description = $this->description( |
||
| 162 | $type, |
||
| 163 | $attr, |
||
| 164 | $locale |
||
| 165 | ); |
||
| 166 | |||
| 167 | $res->breadcrumb = null; |
||
| 168 | if (isset($attr['breadcrumb'])) { |
||
| 169 | $res->breadcrumb = $this->breadcrumb($attr['breadcrumb']); |
||
| 170 | } |
||
| 171 | |||
| 172 | switch ($type) { |
||
| 173 | case 'product': |
||
| 174 | $res->json = \JsonLd\Context::create('product', [ |
||
| 175 | 'name' => $attr['name'], |
||
| 176 | 'description' => $attr['description'], |
||
| 177 | 'brand' => $brand, |
||
| 178 | 'sku' => $attr['sku'], |
||
| 179 | 'url' => $attr['url'], |
||
| 180 | 'offers' => [ |
||
| 181 | 'price' => $attr['price'], |
||
| 182 | 'priceCurrency' => $attr['currency'], |
||
| 183 | ], |
||
| 184 | 'category' => $attr['category'], |
||
| 185 | ]); |
||
| 186 | |||
| 187 | $res->og = new OpenGraph(); |
||
| 188 | $res->og |
||
| 189 | ->type('product') |
||
| 190 | ->title($res->title) |
||
| 191 | ->image($attr['image_url']) |
||
| 192 | ->siteName($attr['site_name']) |
||
| 193 | ->description($res->description) |
||
|
|
|||
| 194 | ->url($attr['url']) |
||
| 195 | ; |
||
| 196 | |||
| 197 | break; |
||
| 198 | |||
| 199 | case 'article': |
||
| 200 | $res->json = \JsonLd\Context::create('article', [ |
||
| 201 | 'headline' => $attr['name'], |
||
| 202 | 'image' => $attr['image_url'], |
||
| 203 | 'author' => [ |
||
| 204 | 'name' => $attr['author'], |
||
| 205 | ], |
||
| 206 | 'publisher' => [ |
||
| 207 | 'name' => $attr['publisher'], |
||
| 208 | ], |
||
| 209 | 'mainEntityOfPage' => $attr['url'], |
||
| 210 | 'datePublished' => $attr['published_at'], |
||
| 211 | 'dateCreated' => $attr['created_at'], |
||
| 212 | 'dateModified' => $attr['modified_at'], |
||
| 213 | 'description' => $res->description, |
||
| 214 | ]); |
||
| 215 | |||
| 216 | $res->og = new OpenGraph(); |
||
| 217 | $res->og |
||
| 218 | ->type('article') |
||
| 219 | ->title($res->title) |
||
| 220 | ->image($attr['image_url']) |
||
| 221 | ->siteName($attr['site_name']) |
||
| 222 | ->description($res->description) |
||
| 223 | ->url($attr['url']) |
||
| 224 | ; |
||
| 225 | |||
| 226 | break; |
||
| 227 | } |
||
| 228 | |||
| 229 | return $res; |
||
| 230 | } |
||
| 232 |