Completed
Pull Request — develop (#305)
by Wachter
15:11
created

ArticleRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 36
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A create() 0 4 1
A save() 0 4 1
A get() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sulu\Bundle\ArticleBundle\Prooph\Infrastruture;
6
7
use Prooph\EventSourcing\Aggregate\AggregateRepository;
8
use Prooph\EventSourcing\Aggregate\AggregateType;
9
use Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator;
10
use Prooph\EventStore\EventStore;
11
use Prooph\SnapshotStore\SnapshotStore;
12
use Sulu\Bundle\ArticleBundle\Prooph\Model\Article;
13
use Sulu\Bundle\ArticleBundle\Prooph\Model\ArticleRepositoryInterface;
14
15
class ArticleRepository extends AggregateRepository implements ArticleRepositoryInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    private $className;
21
22
    public function __construct(string $className, EventStore $eventStore, SnapshotStore $snapshotStore)
23
    {
24
        parent::__construct(
25
            $eventStore,
26
            AggregateType::fromAggregateRootClass($className),
27
            new AggregateTranslator(),
28
            $snapshotStore,
29
            null,
30
            true
31
        );
32
33
        $this->className = $className;
34
    }
35
36
    public function create(string $id, int $userId): Article
37
    {
38
        return $this->className::create($id, $userId);
0 ignored issues
show
Bug introduced by
The method create cannot be called on $this->className (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
39
    }
40
41
    public function save(Article $article): void
42
    {
43
        $this->saveAggregateRoot($article);
44
    }
45
46
    public function get(string $id): ?Article
47
    {
48
        return $this->getAggregateRoot($id);
49
    }
50
}
51