Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
70.37% |
19 / 27 |
|
35.71% |
5 / 14 |
|
23.08% |
3 / 13 |
|
20.00% |
2 / 10 |
CRAP | |
0.00% |
0 / 1 |
| DoctrineStoredFile | |
70.37% |
19 / 27 |
|
35.71% |
5 / 14 |
|
23.08% |
3 / 13 |
|
20.00% |
2 / 10 |
77.54 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFilename | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMimeType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCreatedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toDomain | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromDomain | |
90.00% |
9 / 10 |
|
60.00% |
3 / 5 |
|
25.00% |
1 / 4 |
|
0.00% |
0 / 1 |
6.80 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Shared\Infrastructure\Persistence\Doctrine\Entity; |
| 4 | |
| 5 | use App\Shared\Domain\Model\EntityId; |
| 6 | use App\Shared\Domain\Model\StoredFile; |
| 7 | use Doctrine\ORM\Mapping as ORM; |
| 8 | |
| 9 | /** |
| 10 | * @author Wilhelm Zwertvaegher |
| 11 | */ |
| 12 | |
| 13 | #[ORM\Entity] |
| 14 | #[ORM\Table(name: "stored_files")] |
| 15 | class DoctrineStoredFile |
| 16 | { |
| 17 | #[ORM\Id, ORM\Column(type: "string", length: 36)] |
| 18 | private string $id; |
| 19 | |
| 20 | #[ORM\Column(type: "string", unique: true)] |
| 21 | private string $path; |
| 22 | |
| 23 | #[ORM\Column(type: "string")] |
| 24 | private string $filename; |
| 25 | |
| 26 | #[ORM\Column(type: "string", length: 127)] |
| 27 | private string $mimeType; |
| 28 | |
| 29 | #[ORM\Column(type: "string")] |
| 30 | private string $extension; |
| 31 | |
| 32 | #[ORM\Column(type: "string", length: 40)] |
| 33 | private string $type; |
| 34 | |
| 35 | #[ORM\Column(type: 'datetime_immutable')] |
| 36 | private \DateTimeImmutable $createdAt; |
| 37 | |
| 38 | public function __construct() |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | public function getId(): string |
| 43 | { |
| 44 | return $this->id; |
| 45 | } |
| 46 | |
| 47 | public function getPath(): string |
| 48 | { |
| 49 | return $this->path; |
| 50 | } |
| 51 | |
| 52 | public function getFilename(): string |
| 53 | { |
| 54 | return $this->filename; |
| 55 | } |
| 56 | |
| 57 | public function getMimeType(): string |
| 58 | { |
| 59 | return $this->mimeType; |
| 60 | } |
| 61 | |
| 62 | public function getExtension(): string |
| 63 | { |
| 64 | return $this->extension; |
| 65 | } |
| 66 | |
| 67 | public function getType(): string |
| 68 | { |
| 69 | return $this->type; |
| 70 | } |
| 71 | |
| 72 | public function getCreatedAt(): \DateTimeImmutable |
| 73 | { |
| 74 | return $this->createdAt; |
| 75 | } |
| 76 | |
| 77 | public function toDomain(): StoredFile |
| 78 | { |
| 79 | return new StoredFile( |
| 80 | EntityId::fromString($this->id), |
| 81 | $this->path, |
| 82 | $this->filename, |
| 83 | $this->mimeType, |
| 84 | $this->extension, |
| 85 | $this->type, |
| 86 | $this->createdAt |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | public function fromDomain(StoredFile $storedFile): self |
| 91 | { |
| 92 | if (isset($this->id) && !$storedFile->getId()->valueEquals($this->id)) { |
| 93 | throw new \InvalidArgumentException('Mapping a StoredFile should not change its id'); |
| 94 | } |
| 95 | |
| 96 | $this->id = $storedFile->getId(); |
| 97 | $this->path = $storedFile->getPath(); |
| 98 | $this->filename = $storedFile->getFilename(); |
| 99 | $this->mimeType = $storedFile->getMimeType(); |
| 100 | $this->extension = $storedFile->getExtension(); |
| 101 | $this->type = $storedFile->getType(); |
| 102 | $this->createdAt = $storedFile->getCreatedAt(); |
| 103 | |
| 104 | return $this; |
| 105 | } |
| 106 | } |