Completed
Push — develop ( 335c93...e4583a )
by Mohamed
12:58
created

GlobalIssue::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1.0156
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 Tinyissue\Model;
15
16
/**
17
 * GlobalIssue is a class to defines fields & rules for adding an issue form.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class GlobalIssue extends Issue
22
{
23
    /**
24
     * List of projects.
25
     *
26
     * @var array
27
     */
28
    protected $projects = [];
29
30
    /**
31
     * Returns list of logged in user projects.
32
     *
33
     * @return array
34
     */
35 1
    protected function getProjects()
36
    {
37 1
        if (!$this->projects) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->projects of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
38 1
            $this->projects = $this->user->projects()->get()->lists('name', 'id');
39
        }
40
41
        return $this->projects;
42
    }
43
44
    /**
45
     * @param array $params
46
     *
47
     * @return void
48
     */
49 1
    public function setup(array $params)
50
    {
51 1
        $this->project = new Model\Project();
52 1
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function actions()
58
    {
59
        return [
60
            'submit' => 'create_issue',
61
        ];
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function fields()
68
    {
69
        $fields = $this->fieldTitle();
70
71
        $fields['project'] = [
72
            'type'    => 'select',
73
            'label'   => 'project',
74
            'options' => $this->getProjects()->all(),
0 ignored issues
show
Bug introduced by
The method all cannot be called on $this->getProjects() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
75
        ];
76
77
        $fields += $this->fieldBody();
78
79
        $fields += $this->fieldTypeTags();
80
81
        // Only on creating new issue
82
        $fields += $this->fieldUpload();
83
84
        return $fields;
85
    }
86
87
    /**
88
     * @return array
89
     */
90 1
    public function rules()
91
    {
92 1
        $rules            = parent::rules();
93 1
        $rules['project'] = 'required|in:' . $this->getProjects()->keys()->implode(',');
0 ignored issues
show
Bug introduced by
The method keys cannot be called on $this->getProjects() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
94
95
        return $rules;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getRedirectUrl()
102
    {
103
        return 'projects/new-issue';
104
    }
105
}
106