| Conditions | 22 |
| Paths | 160 |
| Total Lines | 60 |
| 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 |
||
| 24 | public function match(ArticleInterface $article, Criteria $criteria) |
||
| 25 | { |
||
| 26 | if (0 === $criteria->count()) { |
||
| 27 | return false; |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($criteria->has('route')) { |
||
| 31 | foreach ($criteria->get('route') as $value) { |
||
| 32 | if (null !== $article->getRoute() && (int) $value !== $article->getRoute()->getId()) { |
||
| 33 | return false; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($criteria->has('author') && is_array($criteria->get('author'))) { |
||
| 39 | foreach ($criteria->get('author') as $key => $value) { |
||
| 40 | if ($value !== $article->getMetadataByKey('byline')) { |
||
| 41 | return false; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($criteria->has('publishedBefore')) { |
||
| 47 | $publishedBefore = new \DateTime($criteria->get('publishedBefore')); |
||
| 48 | if ($article->getPublishedAt() > $publishedBefore) { |
||
| 49 | return false; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($criteria->has('publishedAfter')) { |
||
| 54 | $publishedAfter = new \DateTime($criteria->get('publishedAfter')); |
||
| 55 | if ($article->getPublishedAt() < $publishedAfter) { |
||
| 56 | return false; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($criteria->has('publishedAt') |
||
| 61 | && (!$criteria->has('publishedBefore') || !$criteria->has('publishedAfter'))) { |
||
| 62 | $publishedAt = new \DateTime($criteria->get('publishedAt')); |
||
| 63 | if ($publishedAt->format('d-m-Y') !== $article->getPublishedAt()->format('d-m-Y')) { |
||
| 64 | return false; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if ($criteria->has('metadata') && !empty($criteria->get('metadata'))) { |
||
| 69 | $criteriaMetadata = $criteria->get('metadata'); |
||
| 70 | |||
| 71 | if (!is_array($criteriaMetadata)) { |
||
| 72 | return false; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($this->isArticleMetadataMatchingCriteria($criteriaMetadata, $article)) { |
||
| 76 | return true; |
||
| 77 | } |
||
| 78 | |||
| 79 | return false; |
||
| 80 | } |
||
| 81 | |||
| 82 | return true; |
||
| 83 | } |
||
| 84 | |||
| 131 |