Passed
Push — master ( aaaee4...c2a29b )
by Mihail
04:03
created

FormCommentDelete   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 1
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A make() 0 11 3
A getRecord() 0 4 1
1
<?php
2
3
namespace Apps\Model\Admin\Comments;
4
5
use Ffcms\Core\Arch\Model;
6
7
class FormCommentDelete extends Model
8
{
9
    private $_record;
10
    private $_type;
11
   
12
    /**
13
     * FormCommentDelete constructor. Pass active record and type of comment system inside.
14
     * @param object $record
15
     * @param string $type
16
     */
17
    public function __construct($record, $type)
18
    {
19
        $this->_record = $record;
20
        $this->_type = $type;
21
        parent::__construct();
22
    }
23
24
    /**
25
     * Make delete items after submit
26
     */
27
    public function make()
28
    {
29
        // also delete all answers
30
        if ($this->_type === 'comment') {
31
            foreach ($this->_record->get() as $com) {
32
                $com->getAnswer()->delete();
33
            }
34
        }
35
        
36
        $this->_record->delete();
37
    }
38
    
39
    /**
40
     * Get records to delete as object
41
     * @return object
42
     */
43
    public function getRecord()
44
    {
45
        return $this->_record->get();
46
    }
47
}