MediaRepository::byId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Media\Doctrine\Orm;
6
7
use Damax\Common\Doctrine\Orm\OrmRepositoryTrait;
8
use Damax\Media\Domain\Model\Media;
9
use Damax\Media\Domain\Model\MediaId;
10
use Damax\Media\Domain\Model\MediaRepository as MediaRepositoryInterface;
11
use Doctrine\ORM\EntityManagerInterface;
12
13
final class MediaRepository implements MediaRepositoryInterface
14
{
15
    use OrmRepositoryTrait;
16
17
    public function __construct(EntityManagerInterface $em, string $mediaClassName)
18
    {
19
        $this->em = $em;
20
        $this->className = $mediaClassName;
21
    }
22
23
    public function byId(MediaId $id): ?Media
24
    {
25
        /** @var Media $media */
26
        $media = $this->em->find($this->className, (string) $id);
27
28
        return $media;
29
    }
30
31
    public function add(Media $media): void
32
    {
33
        $this->em->persist($media);
34
        $this->em->flush($media);
35
    }
36
37
    public function update(Media $media): void
38
    {
39
        $this->em->persist($media);
40
        $this->em->flush($media);
41
    }
42
43
    public function remove(Media $media): void
44
    {
45
        $this->em->remove($media);
46
        $this->em->flush($media);
47
    }
48
}
49