Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 14 | class ArticleRepository extends EntityRepository |
||
| 15 | { |
||
| 16 | use StateFullRepositoryTrait; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Get all articles in the repository. |
||
| 20 | * |
||
| 21 | * @param bool $excludeUnpublished Should we get only the published BasePages ? |
||
| 22 | * |
||
| 23 | * @return ArticleRepository |
||
| 24 | */ |
||
| 25 | public function getAll($excludeUnpublished = false) |
||
| 26 | { |
||
| 27 | $this->clearInstance(); |
||
| 28 | $this->qb = $this->getInstance(); |
||
| 29 | |||
| 30 | //If $excludeUnpublished === true, we exclude the non published results |
||
| 31 | if ($excludeUnpublished) { |
||
| 32 | $this->qb |
||
| 33 | ->andWhere('article.status = :status') |
||
| 34 | ->orWhere('article.status = :scheduled_status AND article.publishedAt > :publicationDate') |
||
| 35 | ->setParameter('status', PageStatus::PUBLISHED) |
||
| 36 | ->setParameter('scheduled_status', PageStatus::SCHEDULED) |
||
| 37 | ->setParameter('publicationDate', new \DateTime()); |
||
| 38 | } |
||
| 39 | |||
| 40 | return $this; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Filter repositoy by Blog. |
||
| 45 | * |
||
| 46 | * @return ArticleRepository |
||
| 47 | */ |
||
| 48 | public function filterByBlog(Blog $blog) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get very next festivals query builder. |
||
| 59 | * |
||
| 60 | * @param method $method The method to run |
||
| 61 | * @param hydrationMode $hydrationMode How the results will be (Object ? Array ) |
||
| 62 | * |
||
| 63 | * @return array() |
||
|
|
|||
| 64 | */ |
||
| 65 | public function run($method = 'getResult', $hydrationMode = Query::HYDRATE_OBJECT) |
||
| 69 | |||
| 70 | public function filterWithListingQuery($listingQuery = null) |
||
| 83 | |||
| 84 | View Code Duplication | public function getPreviousRecord($id) |
|
| 96 | |||
| 97 | View Code Duplication | public function getNextRecord($id) |
|
| 109 | |||
| 110 | View Code Duplication | public function getVeryFirstRecord() |
|
| 121 | |||
| 122 | View Code Duplication | public function getVeryLastRecord() |
|
| 133 | } |
||
| 134 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.