Completed
Push — master ( d63f8e...49a1eb )
by Christian
02:29
created

StatementRepository::storeStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace XApi\Repository\Doctrine\Test;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Xabbuh\XApi\Model\Actor;
16
use Xabbuh\XApi\Model\Statement;
17
use Xabbuh\XApi\Model\StatementId;
18
use Xabbuh\XApi\Model\StatementsFilter;
19
use XApi\Repository\Api\StatementRepositoryInterface;
20
21
/**
22
 * Statement repository clearing the object manager between read and write operations.
23
 *
24
 * @author Christian Flothmann <[email protected]>
25
 */
26
final class StatementRepository implements StatementRepositoryInterface
27
{
28
    private $repository;
29
    private $objectManager;
30
31
    public function __construct(StatementRepositoryInterface $repository, ObjectManager $objectManager)
32
    {
33
        $this->repository = $repository;
34
        $this->objectManager = $objectManager;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 View Code Duplication
    public function findStatementById(StatementId $statementId, Actor $authority = null)
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...
41
    {
42
        $statement = $this->repository->findStatementById($statementId, $authority);
43
        $this->objectManager->clear();
44
45
        return $statement;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 View Code Duplication
    public function findVoidedStatementById(StatementId $voidedStatementId, Actor $authority = null)
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...
52
    {
53
        $statement = $this->repository->findVoidedStatementById($voidedStatementId, $authority);
54
        $this->objectManager->clear();
55
56
        return $statement;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function findStatementsBy(StatementsFilter $criteria, Actor $authority = null)
63
    {
64
        $statements = $this->repository->findStatementsBy($criteria, $authority);
65
        $this->objectManager->clear();
66
67
        return $statements;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function storeStatement(Statement $statement, $flush = true)
74
    {
75
        $statementId = $this->repository->storeStatement($statement);
76
        $this->objectManager->clear();
77
78
        return $statementId;
79
    }
80
}
81