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 |
||
| 29 | class ArticleProvider extends AbstractProvider implements ArticleProviderInterface |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @var ArticleRepositoryInterface |
||
| 33 | */ |
||
| 34 | private $articleRepository; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * ArticleProvider constructor. |
||
| 38 | * |
||
| 39 | * @param ArticleRepositoryInterface $articleRepository |
||
| 40 | */ |
||
| 41 | 91 | public function __construct( |
|
| 46 | |||
| 47 | 2 | public function getRepository(): ArticleRepositoryInterface |
|
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | 6 | public function getOneById($id) |
|
| 56 | { |
||
| 57 | 6 | if (!filter_var($id, FILTER_VALIDATE_INT)) { |
|
| 58 | 4 | return $this->articleRepository->findOneBySlug($id); |
|
| 59 | } |
||
| 60 | |||
| 61 | 2 | return $this->articleRepository->findOneBy(['id' => $id]); |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | public function getParent($id) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | public function getRouteArticlesQuery(string $routeIdentifier, array $order) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | 12 | View Code Duplication | public function getOneByCriteria(Criteria $criteria): ArticleInterface |
| 93 | |||
| 94 | /** |
||
| 95 | * {@inheritdoc} |
||
| 96 | */ |
||
| 97 | 2 | public function getCountByCriteria(Criteria $criteria): int |
|
| 101 | } |
||
| 102 |