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

DeleteArticleHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sulu\Bundle\ArticleBundle\Prooph\Model\Handler;
6
7
use Sulu\Bundle\ArticleBundle\Prooph\Model\Article;
8
use Sulu\Bundle\ArticleBundle\Prooph\Model\ArticleRepositoryInterface;
9
use Sulu\Bundle\ArticleBundle\Prooph\Model\Command\DeleteArticleCommand;
10
11
class DeleteArticleHandler
12
{
13
    /**
14
     * @var ArticleRepositoryInterface
15
     */
16
    private $repository;
17
18
    public function __construct(ArticleRepositoryInterface $repository)
19
    {
20
        $this->repository = $repository;
21
    }
22
23
    public function __invoke(DeleteArticleCommand $command): void
24
    {
25
        $article = $this->repository->get($command->id());
26
27
        $article = $article->remove($command->userId());
28
        $this->repository->save($article);
29
    }
30
}
31