| Total Complexity | 7 |
| Total Lines | 94 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 |
||
| 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 |
||
| 108 | } |
||
| 109 | } |
||
| 110 |