Completed
Push — develop ( e210c1...b7d5d2 )
by Mohamed
07:16 queued 59s
created

Comment   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 7
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 76
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 8 1
A fields() 0 16 2
A setup() 0 5 1
A actions() 0 6 2
A getRedirectUrl() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Form;
13
14
/**
15
 * Comment is a class to defines fields & rules for add/edit comments form.
16
 *
17
 * @author Mohamed Alsharaf <[email protected]>
18
 */
19
class Comment extends FormAbstract
20
{
21
    /**
22
     * An instance of project model.
23
     *
24
     * @var \Tinyissue\Model\Project
25
     */
26
    protected $project;
27
    /**
28
     * An instance of project issue model.
29
     *
30
     * @var \Tinyissue\Model\Project\issue
31
     */
32
    protected $issue;
33
34
    /**
35
     * @param array $params
36
     *
37
     * @return void
38
     */
39 11
    public function setup(array $params)
40
    {
41 11
        $this->project = $params['project'];
42 11
        $this->issue   = $params['issue'];
43 11
    }
44
45
    /**
46
     * @return array
47
     */
48 11
    public function actions()
49
    {
50
        return [
51 11
            'submit' => $this->isEditing() ? 'update' : 'comment',
52
        ];
53
    }
54
55
    /**
56
     * @return array
57
     */
58 11
    public function fields()
59
    {
60
        $fields = [
61
            'comment' => [
62
                'type' => 'textarea',
63
                'help' => '<a href="http://daringfireball.net/projects/markdown/basics/" target="_blank">Format with Markdown</a>',
64 11
            ],
65
        ];
66
67
        // Only for adding new comment
68 11
        if (!$this->isEditing()) {
69 11
            $fields += $this->projectUploadFields('upload', $this->project, \Auth::user());
70
        }
71
72 11
        return $fields;
73
    }
74
75
    /**
76
     * @return array
77
     */
78 11
    public function rules()
79
    {
80
        $rules = [
81 11
            'comment' => 'required',
82
        ];
83
84 11
        return $rules;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getRedirectUrl()
91
    {
92
        return $this->issue->to();
93
    }
94
}
95