Passed
Push — master ( 501fc3...f64e27 )
by Paweł
47:53
created

ArticleProvider::getRouteArticlesQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Provider\ORM;
18
19
use SWP\Bundle\ContentBundle\Provider\AbstractProvider;
20
use SWP\Component\Common\Criteria\Criteria;
21
use SWP\Bundle\ContentBundle\Doctrine\ArticleRepositoryInterface;
22
use SWP\Bundle\ContentBundle\Model\ArticleInterface;
23
use SWP\Bundle\ContentBundle\Provider\ArticleProviderInterface;
24
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
25
26
/**
27
 * ArticleProvider to provide articles from ORM.
28
 */
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 93
    public function __construct(
42
        ArticleRepositoryInterface $articleRepository
43
    ) {
44 93
        $this->articleRepository = $articleRepository;
45 93
    }
46
47 2
    public function getRepository(): ArticleRepositoryInterface
48
    {
49 2
        return $this->articleRepository;
50
    }
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)
68
    {
69
        return $this->articleRepository->find($id);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getRouteArticlesQuery(string $routeIdentifier, array $order)
76
    {
77
        return $this->articleRepository->getQueryForRouteArticles($routeIdentifier, $order);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 12 View Code Duplication
    public function getOneByCriteria(Criteria $criteria): ArticleInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85 12
        $criteria->set('maxResults', 1);
86 12
        $article = $this->articleRepository->getByCriteria($criteria, [])->getQuery()->getOneOrNullResult();
87 12
        if (null === $article) {
88 2
            throw new NotFoundHttpException('Article was not found');
89
        }
90
91 11
        return $article;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 2
    public function getCountByCriteria(Criteria $criteria): int
98
    {
99 2
        return $this->articleRepository->countByCriteria($criteria);
100
    }
101
}
102