Completed
Push — master ( 91f8d9...64265e )
by Mohamed
09:45 queued 06:57
created

GlobalIssue::getProjects()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
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
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 = \Auth::user()->projects()->get()->lists('name', 'id');
39
        }
40
41 1
        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 1
    public function actions()
58
    {
59
        return [
60 1
            'submit' => 'create_issue',
61
        ];
62
    }
63
64
    /**
65
     * @return array
66
     */
67 1
    public function fields()
68
    {
69 1
        $fields = $this->fieldTitle();
70
71 1
        $fields['project'] = [
72 1
            'type'    => 'select',
73 1
            'label'   => 'project',
74 1
            '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 1
        $fields += $this->fieldBody();
78
79 1
        $fields += $this->fieldTypeTags();
80
81
        // Only on creating new issue
82 1
        $fields += $this->fieldUpload();
83
84 1
        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 1
        return $rules;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getRedirectUrl()
102
    {
103
        return 'projects/new-issue';
104
    }
105
}
106