BaseProcessor::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Itstructure\MFU\Processors;
4
5
use Exception;
6
use Illuminate\Support\MessageBag;
7
use Itstructure\MFU\Models\Mediafile;
8
9
/**
10
 * Class BaseProcessor
11
 * @package Itstructure\MFU\Processors
12
 * @author Andrey Girnik <[email protected]>
13
 */
14
abstract class BaseProcessor
15
{
16
    /************************* PROCESS ATTRIBUTES *************************/
17
    /**
18
     * @var string
19
     */
20
    protected $currentDisk;
21
22
    /**
23
     * @var Mediafile
24
     */
25
    protected $mediafileModel;
26
27
    /**
28
     * @var string
29
     */
30
    protected $processDirectory;
31
32
    /**
33
     * @var MessageBag|null
34
     */
35
    protected $errors;
36
37
38
    /************************* ABSTRACT METHODS ***************************/
39
    abstract protected function setProcessParams(): void;
40
41
    /**
42
     * @throws Exception
43
     * @return bool
44
     */
45
    abstract protected function process(): bool;
46
47
    abstract protected function afterProcess(): void;
48
49
50
    /********************** PROCESS PUBLIC METHODS ***********************/
51
    /**
52
     * @param array $config
53
     * @return static
54
     */
55
    public static function getInstance(array $config = [])
56
    {
57
        $obj = new static();
58
        foreach ($config as $key => $value) {
59
            $obj->{'set' . ucfirst($key)}($value);
60
        }
61
        return $obj;
62
    }
63
64
    /**
65
     * @throws Exception
66
     * @return bool
67
     */
68
    public function run(): bool
69
    {
70
        $this->setProcessParams();
71
        $this->process();
72
        $this->afterProcess();
73
        return true;
74
    }
75
76
    /**
77
     * @param Mediafile $model
78
     * @return $this
79
     */
80
    public function setMediafileModel(Mediafile $model)
81
    {
82
        $this->mediafileModel = $model;
83
        return $this;
84
    }
85
86
    /**
87
     * @return Mediafile
88
     */
89
    public function getMediafileModel(): Mediafile
90
    {
91
        return $this->mediafileModel;
92
    }
93
94
    /**
95
     * @return int
96
     */
97
    public function getId()
98
    {
99
        return $this->mediafileModel->id;
100
    }
101
102
    /**
103
     * @return MessageBag|null
104
     */
105
    public function getErrors(): ?MessageBag
106
    {
107
        return $this->errors;
108
    }
109
}
110