HasFileModel::setFileModelData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NovaResourceDynamicExport\Export;
4
5
use NovaResourceDynamicExport\Models\ExportStoredFile;
6
7
trait HasFileModel
8
{
9
    protected string $fileModelData = '';
10
11 1
    public function useStoreFile(ExportStoredFile $file): static
12
    {
13 1
        return $this->setFileModelData(serialize($file));
14
    }
15
16 1
    public function setFileModelData(string $fileModelData): static
17
    {
18 1
        $this->fileModelData = $fileModelData;
19
20 1
        return $this;
21
    }
22
23 1
    protected function saveFileFromModel(): ?ExportStoredFile
24
    {
25 1
        $fileModel = null;
26 1
        if ($this->fileModelData) {
27 1
            $fileModel = unserialize($this->fileModelData);
28 1
            if ($fileModel instanceof ExportStoredFile) {
29 1
                $fileModel->save();
30
            }
31
        }
32
33 1
        return $fileModel;
34
    }
35
}
36