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

Comment::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 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