Completed
Push — develop ( a45eac...0b88af )
by Mohamed
02:46
created

Comment::getRedirectUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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 18
    public function setup(array $params)
40
    {
41 18
        $this->project = $params['project'];
42 18
        $this->issue   = $params['issue'];
43 18
    }
44
45
    /**
46
     * @return array
47
     */
48 15
    public function actions()
49
    {
50
        return [
51 15
            'submit' => $this->isEditing() ? 'update' : 'comment',
52 15
        ];
53
    }
54
55
    /**
56
     * @return array
57
     */
58 15
    public function fields()
59
    {
60
        $fields = [
61
            'comment' => [
62 15
                'type' => 'textarea',
63 15
                'help' => '<a href="http://daringfireball.net/projects/markdown/basics/" target="_blank">Format with Markdown</a>',
64 15
            ],
65 15
        ];
66
67
        // Only for adding new comment
68 15
        if (!$this->isEditing()) {
69 15
            $fields += $this->projectUploadFields('upload', $this->project, \Auth::user());
70 15
        }
71
72 15
        return $fields;
73
    }
74
75
    /**
76
     * @return array
77
     */
78 15
    public function rules()
79
    {
80
        $rules = [
81 15
            'comment' => 'required',
82 15
        ];
83
84 15
        return $rules;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getRedirectUrl()
91
    {
92
        return $this->issue->to();
93
    }
94
}
95