HasFileModel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A saveFileFromModel() 0 11 3
A setFileModelData() 0 5 1
A useStoreFile() 0 3 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