Completed
Pull Request — master (#414)
by
unknown
03:33
created

handleMarkAsDuplicate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Place;
4
5
use CultuurNet\UDB3\CommandHandling\Udb3CommandHandler;
6
use CultuurNet\UDB3\Place\Commands\MarkAsDuplicate;
7
8
class MarkAsDuplicateCommandHandler extends Udb3CommandHandler
9
{
10
    /**
11
     * @var PlaceRepository
12
     */
13
    private $repository;
14
15
    public function __construct(PlaceRepository $repository)
16
    {
17
        $this->repository = $repository;
18
    }
19
20
    public function handleMarkAsDuplicate(MarkAsDuplicate $command): void
21
    {
22
        /* @var Place $placeToMarkAsDuplicate */
23
        $placeToMarkAsDuplicate = $this->repository->load($command->getDuplicatePlaceId());
24
25
        /* @var Place $placeToMarkAsMaster */
26
        $placeToMarkAsMaster = $this->repository->load($command->getCanonicalPlaceId());
27
28
        $placeToMarkAsDuplicate->markAsDuplicateOf($command->getCanonicalPlaceId());
29
        $placeToMarkAsMaster->markAsCanonicalFor($command->getDuplicatePlaceId());
30
31
        $this->repository->saveMultiple($placeToMarkAsDuplicate, $placeToMarkAsMaster);
32
    }
33
}
34