Conditions | 10 |
Paths | 13 |
Total Lines | 35 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
17 | public function filterSchema($graph): array |
||
18 | { |
||
19 | $graph = Arr::consolidate($graph); |
||
20 | if (function_exists('is_product') && is_product()) { |
||
21 | return $graph; // skip WooCommerce products |
||
22 | } |
||
23 | $schema = glsr(Schema::class)->generate(); |
||
24 | if (empty($schema)) { |
||
25 | return $graph; |
||
26 | } |
||
27 | $allowedTypes = glsr(RatingSchemaTypeDefaults::class)->defaults(); |
||
28 | $aggregateRatingSchema = Arr::get($schema, 'aggregateRating'); |
||
29 | $reviewSchema = Arr::get($schema, 'review'); |
||
30 | foreach ($graph as $key => $item) { |
||
31 | $types = Arr::getAs('array', $item, '@type'); |
||
32 | if (empty(array_intersect($types, $allowedTypes))) { |
||
33 | continue; |
||
34 | } |
||
35 | $isReviewType = !empty(array_intersect($types, ['Review', 'ReviewNewsArticle'])); |
||
36 | if (!empty($aggregateRatingSchema)) { |
||
37 | if ($isReviewType) { |
||
38 | $graph[$key]['itemReviewed']['aggregateRating'] = $aggregateRatingSchema; |
||
39 | } else { |
||
40 | $graph[$key]['aggregateRating'] = $aggregateRatingSchema; |
||
41 | } |
||
42 | } |
||
43 | if (!empty($reviewSchema)) { |
||
44 | if ($isReviewType) { |
||
45 | $graph[$key]['itemReviewed']['review'] = $reviewSchema; |
||
46 | } else { |
||
47 | $graph[$key]['review'] = $reviewSchema; |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | return $graph; |
||
52 | } |
||
54 |