GlobalIssue   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRedirectUrl() 0 4 1
A getProjects() 0 8 2
A setup() 0 4 1
A actions() 0 6 1
A rules() 0 7 1
A fields() 0 19 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
use Illuminate\Support\Collection;
15
use Tinyissue\Model;
16
17
/**
18
 * GlobalIssue is a class to defines fields & rules for adding an issue form.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 */
22
class GlobalIssue extends Issue
23
{
24
    /**
25
     * List of projects.
26
     *
27
     * @var array
28
     */
29
    protected $projects;
30
31
    /**
32
     * Returns list of logged in user projects.
33
     *
34
     * @return Collection
35
     */
36 1
    protected function getProjects()
37
    {
38 1
        if (is_null($this->projects)) {
39 1
            $this->projects = $this->getLoggedUser()->projects()->get()->lists('name', 'id');
40
        }
41
42 1
        return $this->projects;
43
    }
44
45
    /**
46
     * @param array $params
47
     *
48
     * @return void
49
     */
50 1
    public function setup(array $params)
51
    {
52 1
        $this->project = new Model\Project();
53 1
    }
54
55
    /**
56
     * @return array
57
     */
58 1
    public function actions()
59
    {
60
        return [
61 1
            'submit' => 'create_issue',
62
        ];
63
    }
64
65
    /**
66
     * @return array
67
     */
68 1
    public function fields()
69
    {
70 1
        $fields = $this->fieldTitle();
71
72 1
        $fields['project'] = [
73 1
            'type'    => 'select',
74 1
            'label'   => 'project',
75 1
            'options' => $this->getProjects()->all(),
76
        ];
77
78 1
        $fields += $this->fieldBody();
79
80 1
        $fields += $this->fieldTag('type');
81
82
        // Only on creating new issue
83 1
        $fields += $this->fieldUpload();
84
85 1
        return $fields;
86
    }
87
88
    /**
89
     * @return array
90
     */
91 1
    public function rules()
92
    {
93 1
        $rules            = parent::rules();
94 1
        $rules['project'] = 'required|in:' . $this->getProjects()->keys()->implode(',');
95
96 1
        return $rules;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getRedirectUrl()
103
    {
104
        return 'projects/new-issue';
105
    }
106
}
107