ByTIC /
payments
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace ByTIC\Payments\Controllers\Traits; |
||||||
| 4 | |||||||
| 5 | use ByTIC\Payments\Models\Methods\Traits\RecordsTrait; |
||||||
| 6 | use ByTIC\Payments\Models\Methods\Traits\RecordTrait; |
||||||
| 7 | use Nip\Records\AbstractModels\Record; |
||||||
| 8 | use Nip\Records\AbstractModels\RecordManager; |
||||||
| 9 | use Symfony\Component\HttpFoundation\Request; |
||||||
| 10 | |||||||
| 11 | /** |
||||||
| 12 | * Class AdminPaymentMethodsTrait |
||||||
| 13 | * @package ByTIC\Payments\Payments\Controllers\Traits |
||||||
| 14 | */ |
||||||
| 15 | trait AdminPaymentMethodsTrait |
||||||
| 16 | { |
||||||
| 17 | public function deleteFile() |
||||||
| 18 | { |
||||||
| 19 | $item = $this->getModelFromRequest(); |
||||||
| 20 | $fileName = $this->getRequest()->get('file'); |
||||||
| 21 | |||||||
| 22 | $type = 'error'; |
||||||
| 23 | $message = $this->getModelManager()->getMessage('deleteFile.error'); |
||||||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||||||
| 24 | if ($fileName) { |
||||||
| 25 | $files = $item->getFiles(); |
||||||
| 26 | if ($files[$fileName]) { |
||||||
| 27 | $files[$fileName]->delete(); |
||||||
| 28 | $type = 'success'; |
||||||
| 29 | $message = $this->getModelManager()->getMessage('deleteFile.success'); |
||||||
| 30 | } else { |
||||||
| 31 | $message = $this->getModelManager()->getMessage('deleteFile.no-file'); |
||||||
| 32 | } |
||||||
| 33 | } else { |
||||||
| 34 | $message = $this->getModelManager()->getMessage('deleteFile.no-filename'); |
||||||
| 35 | } |
||||||
| 36 | $this->flashRedirect($message, $item->compileURL('view'), $type); |
||||||
|
0 ignored issues
–
show
It seems like
compileURL() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 37 | } |
||||||
| 38 | |||||||
| 39 | /** |
||||||
| 40 | * @param bool $key |
||||||
| 41 | * @return Record|RecordTrait |
||||||
| 42 | */ |
||||||
| 43 | abstract protected function getModelFromRequest($key = false); |
||||||
| 44 | |||||||
| 45 | /** |
||||||
| 46 | * @return Request |
||||||
| 47 | */ |
||||||
| 48 | abstract protected function getRequest(); |
||||||
| 49 | |||||||
| 50 | /** |
||||||
| 51 | * @return RecordManager|RecordsTrait |
||||||
| 52 | */ |
||||||
| 53 | abstract protected function getModelManager(); |
||||||
| 54 | |||||||
| 55 | /** |
||||||
| 56 | * @param $message |
||||||
| 57 | * @param $url |
||||||
| 58 | * @param string $type |
||||||
| 59 | * @param bool $name |
||||||
| 60 | * @return mixed |
||||||
| 61 | */ |
||||||
| 62 | abstract protected function flashRedirect($message, $url, $type = 'success', $name = false); |
||||||
| 63 | |||||||
| 64 | public function delete() |
||||||
| 65 | { |
||||||
| 66 | $item = $this->getModelFromRequest(); |
||||||
| 67 | |||||||
| 68 | $deleteMessage = $item->canDelete(); |
||||||
| 69 | if ($deleteMessage !== true) { |
||||||
| 70 | $url = $item->getURL(); |
||||||
|
0 ignored issues
–
show
It seems like
getURL() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 71 | $this->_flashName = $this->getModelManager()->getController(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 72 | $this->flashRedirect($deleteMessage, $url, 'error', $this->_flashName); |
||||||
|
0 ignored issues
–
show
$this->_flashName of type string is incompatible with the type boolean expected by parameter $name of ByTIC\Payments\Controlle...sTrait::flashRedirect().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | parent::delete(); |
||||||
| 76 | } |
||||||
| 77 | } |
||||||
| 78 |