Passed
Push — master ( 81f334...c86e8c )
by Mihail
03:35
created

ActionDelete   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B delete() 0 24 6
1
<?php
2
3
namespace Apps\Controller\Admin\Content;
4
5
use Apps\Model\Admin\Content\FormContentDelete;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Exception\NotFoundException;
9
use Ffcms\Core\Helper\Type\Any;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
use Apps\ActiveRecord\Content as ContentEntity;
13
14
/**
15
 * Trait ActionDelete
16
 * @package Apps\Controller\Admin\Content
17
 * @property Request $request
18
 * @property Response $response
19
 * @property View $view
20
 */
21
trait ActionDelete
22
{
23
    /**
24
     * Delete content by id
25
     * @param string $id
26
     * @return string
27
     * @throws \Exception
28
     */
29
    public function delete(string $id): ?string
30
    {
31
        if (!Any::isInt($id) || $id < 1) {
32
            throw new NotFoundException();
33
        }
34
35
        // get content record and check availability
36
        $record = ContentEntity::find($id);
37
        if ($record === null) {
38
            throw new NotFoundException();
39
        }
40
41
        // init delete model
42
        $model = new FormContentDelete($record);
43
        if ($model->send() && $model->validate()) {
44
            $model->make();
45
            App::$Session->getFlashBag()->add('success', __('Content is successful moved to trash'));
46
            $this->response->redirect('content/index');
47
        }
48
49
        return $this->view->render('content_delete', [
50
            'model' => $model
51
        ]);
52
    }
53
}
54