FileDTODataTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 7 2
A read() 0 16 2
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\File\Application\DataTransformer;
14
15
use BenGorFile\File\Domain\Model\File;
16
17
/**
18
 * File DTO data transformer.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
class FileDTODataTransformer implements FileDataTransformer
23
{
24
    /**
25
     * The domain file.
26
     *
27
     * @var File
28
     */
29
    protected $file;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function write($aFile)
35
    {
36
        if (!$aFile instanceof File) {
37
            throw new \InvalidArgumentException(sprintf('Expected instance of %s', File::class));
38
        }
39
        $this->file = $aFile;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function read()
46
    {
47
        if (null === $this->file) {
48
            return [];
49
        }
50
51
        return [
52
            'id'         => $this->file->id()->id(),
53
            'created_on' => $this->file->createdOn(),
54
            'mime_type'  => $this->file->mimeType()->mimeType(),
55
            'file_name'  => $this->file->name()->filename(),
56
            'name'       => $this->file->name()->name(),
57
            'extension'  => $this->file->name()->extension(),
58
            'updated_on' => $this->file->updatedOn(),
59
        ];
60
    }
61
}
62