Test Failed
Push — master ( 004faa...c8ffdf )
by Maximo
11:48 queued 05:52
created

FileMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Mapper;
6
7
use AutoMapperPlus\CustomMapper\CustomMapper;
8
use Canvas\Dto\Files;
9
use Canvas\Models\FileSystemEntities;
10
11
// You can either extend the CustomMapper, or just implement the MapperInterface
12
// directly.
13
class FileMapper extends CustomMapper
14
{
15
    public $systemModuleId;
16
    public $entityId;
17
18
    /**
19
     * constructor.
20
     *
21
     * @param integer $entityId
22
     * @param integer $systemModuleId
23
     */
24
    public function __construct(int $entityId, int $systemModuleId)
25
    {
26
        $this->systemModuleId = $systemModuleId;
27
        $this->entityId = $entityId;
28
    }
29
30
    /**
31
     * @param Canvas\Models\FileSystem $file
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Canvas\Models\FileSystem was not found. Did you mean Canvas\Models\FileSystem? If so, make sure to prefix the type with \.
Loading history...
32
     * @param Canvas\Dto\Files $fileDto
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Canvas\Dto\Files was not found. Did you mean Canvas\Dto\Files? If so, make sure to prefix the type with \.
Loading history...
33
     * @return Files
34
     */
35
    public function mapToObject($file, $fileDto, array $context = [])
36
    {
37
        $fileEntity = FileSystemEntities::findFirst([
38
            'conditions' => 'system_modules_id = ?0 AND entity_id = ?1 AND filesystem_id = ?2 AND companies_id = ?3 AND is_deleted = 0',
39
            'bind' => [$this->systemModuleId, $this->entityId, $file->getId(), $file->companies_id]
40
        ]);
41
42
        $fileDto->id = $fileEntity->getId();
43
        $fileDto->filesystem_id = $file->getId();
44
        $fileDto->name = $file->name;
45
        $fileDto->field_name = $fileEntity ? $fileEntity->field_name : null;
46
        $fileDto->url = $file->url;
47
        $fileDto->size = $file->size;
48
        $fileDto->file_type = $file->file_type;
49
        $fileDto->attributes = $file->getAllSettings();
50
51
        return $fileDto;
52
    }
53
}
54