Passed
Push — master ( cc7747...d2190f )
by Mihail
10:36
created

FormContentDelete   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A before() 0 5 1
A labels() 0 6 1
A make() 0 6 1
1
<?php
2
3
namespace Apps\Model\Admin\Content;
4
5
use Apps\ActiveRecord\Content;
6
use Ffcms\Core\Arch\Model;
7
use Ffcms\Core\Helper\Serialize;
8
9
/**
10
 * Class FormContentDelete. Delete content item business logic
11
 * @package Apps\Model\Admin\Content
12
 */
13
class FormContentDelete extends Model
14
{
15
    public $id;
16
    public $title;
17
18
    private $_record;
19
20
    /**
21
     * FormContentDelete constructor. Pass object in model on init
22
     * @param Content $record
23
     */
24
    public function __construct(Content $record)
25
    {
26
        $this->_record = $record;
27
        parent::__construct();
28
    }
29
30
    /**
31
     * Set readable title of content to property
32
     */
33
    public function before()
34
    {
35
        $this->id = $this->_record->id;
36
        $this->title = Serialize::getDecodeLocale($this->_record->title);
37
    }
38
39
    /**
40
     * Form display labels
41
     * @return array
42
     */
43
    public function labels()
44
    {
45
        return [
46
            'title' => __('Title')
47
        ];
48
    }
49
50
    /**
51
     * Make delete
52
     * @throws \Exception
53
     */
54
    public function make()
55
    {
56
        $this->_record->getTags()->delete();
57
        $this->_record->getRating()->delete();
58
        $this->_record->delete();
59
    }
60
}