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

ArticleRepository::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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