Completed
Push — master ( fecb59...e32f72 )
by Paweł
29:36
created

ArticleProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 54
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getOneById() 0 8 2
A getParent() 0 4 1
A getRouteArticlesQuery() 0 4 1
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;
18
19
use Jackalope\Query\SqlQuery;
20
use SWP\Bundle\ContentBundle\Doctrine\ArticleRepositoryInterface;
21
use SWP\Component\MultiTenancy\PathBuilder\TenantAwarePathBuilderInterface;
22
23
/**
24
 * ArticleProvider to provide articles based on PHPCR paths.
25
 */
26
class ArticleProvider implements ArticleProviderInterface
27
{
28
    /**
29
     * @var ArticleRepositoryInterface
30
     */
31
    private $articleRepository;
32
33
    /**
34
     * @var TenantAwarePathBuilderInterface
35
     */
36
    private $pathBuilder;
37
38
    /**
39
     * ArticleProvider constructor.
40
     *
41
     * @param ArticleRepositoryInterface      $articleRepository
42
     * @param TenantAwarePathBuilderInterface $pathBuilder
43
     */
44 98
    public function __construct(
45
        ArticleRepositoryInterface $articleRepository,
46
        TenantAwarePathBuilderInterface $pathBuilder
47
    ) {
48 98
        $this->articleRepository = $articleRepository;
49 98
        $this->pathBuilder = $pathBuilder;
50 98
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 18
    public function getOneById($id)
56
    {
57 18
        if (!filter_var($id, FILTER_VALIDATE_INT)) {
58 18
            return $this->articleRepository->findOneBySlug($id);
59
        }
60
61
        return $this->articleRepository->findOneBy(['id' => $id]);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 13
    public function getParent($id)
68
    {
69 13
        return $this->articleRepository->find($this->pathBuilder->build($id));
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 6
    public function getRouteArticlesQuery(string $routeIdentifier, array $order) : SqlQuery
76
    {
77 6
        return $this->articleRepository->getQueryForRouteArticles($routeIdentifier, $order);
78
    }
79
}
80