Completed
Pull Request — dev (#314)
by Tristan
06:49
created

JobController::create()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 70
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 70
ccs 0
cts 12
cp 0
rs 8.9818
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Lang;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Http\Request;
8
use Barryvdh\Debugbar\Facade as Debugbar;
9
use App\Http\Controllers\Controller;
10
use Carbon\Carbon;
11
use App\Models\JobPoster;
12
use App\Models\Lookup\JobTerm;
13
use App\Models\Lookup\Province;
14
use App\Models\Lookup\SecurityClearance;
15
use App\Models\Lookup\LanguageRequirement;
16
use App\Models\Lookup\Department;
17
use App\Models\JobPosterQuestion;
18
use App\Models\JobPosterKeyTask;
19
use Jenssegers\Date\Date;
20
21
class JobController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JobController
Loading history...
22
{
23
    /**
24
     * Display a listing of JobPosters.
25
     *
26
     * @return \Illuminate\Http\Response
27
     */
28
    public function index()
29
    {
30
        $now = Carbon::now();
31
        //Find published jobs that are currently open for applications
32
        $jobs = JobPoster::where('open_date_time', '<=', $now)
33
            ->where('close_date_time', '>=', $now)
34
            ->where('published', true)
35
            ->get();
36
        return view('applicant/job_index', ['job_index' => Lang::get('applicant/job_index'),
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Bug Best Practice introduced by
The expression return view('applicant/j...ex'), 'jobs' => $jobs)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
37
            'jobs' => $jobs]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
38
    }
39
40
    /**
41
     * Display the specified job poster.
42
     *
43
     * @param  Request  $request
0 ignored issues
show
Coding Style introduced by
Expected 15 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
44
     * @param  \App\Models\JobPoster  $jobPoster
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
45
     * @return \Illuminate\Http\Response
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
46
     */
47
    public function show(Request $request, JobPoster $jobPoster)
48
    {
49
        //TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model
50
        $workplacePhotos = [];
51
        foreach($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
52
            $workplacePhotos[] = [
53
                'description' => $photoCaption->description,
54
                'url' => '/images/user.png'
55
            ];
56
        }
57
58
        //TODO: replace route('manager.show',manager.id) in templates with link using slug
59
60
        $criteria = [
61
            'essential' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
62
                return $value->criteria_type->name == 'essential';
63
            }),
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
64
            'asset' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
65
                return $value->criteria_type->name == 'asset';
66
            })
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
67
        ];
68
69
        return view('applicant/job_post', [
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Bug Best Practice introduced by
The expression return view('applicant/j...riteria' => $criteria)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
70
            'job_post' =>Lang::get('applicant/job_post'),
71
            'manager' => $jobPoster->manager,
72
            'manager_profile_photo_url' => '/images/user.png', //TODO get real photo
73
            'team_culture' => $jobPoster->manager->team_culture,
74
            'work_environment' => $jobPoster->manager->work_environment,
75
            'workplace_photos' => $workplacePhotos,
76
            'job' => $jobPoster,
77
            'criteria' => $criteria,
78
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
79
    }
80
81
    /**
82
     * Display the form for creating a new Job Poster
83
     * @param  Request $request [description]
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
84
     * @return \Illuminate\Http\Response           A view
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
85
     */
86
    public function create(Request $request) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
87
        $manager = $request->user() ? $request->user()->manager : null;
88
89
        //No job details exist yet because we're creating a new one
90
        $job = [];
91
92
        return view('manager/job_create', [
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Bug Best Practice introduced by
The expression return view('manager/job...evel Demonstration')))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
93
            'manager_job_create' => Lang::get('manager/job_create'),
94
            'manager' => $manager,
95
            'provinces' => Province::all(),
96
            'departments' => Department::all(),
97
            'language_requirments' => LanguageRequirement::all(),
98
            'security_clearances' => SecurityClearance::all(),
99
            'job' => $job,
100
            'form_action_url' => route('manager.jobs.store'),
101
            // Fake Data
102
            "skills" => [
103
                "00" => [
104
                    "name" => "UX Research",
105
                    "type" => "soft",
106
                    "description" => "UX: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
107
                ],
108
                "01" => [
109
                    "name" => "HTML",
110
                    "type" => "hard",
111
                    "description" => "HTML: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
112
                ],
113
                "02" => [
114
                    "name" => "CSS",
115
                    "type" => "hard",
116
                    "description" => "CSS: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
117
                ],
118
                "03" => [
119
                    "name" => "Laravel",
120
                    "type" => "hard",
121
                    "description" => "Laravel: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
122
                ],
123
                "04" => [
124
                    "name" => "JavaScript",
125
                    "type" => "soft",
126
                    "description" => "JS: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
127
                ],
128
                "05" => [
129
                    "name" => "Docker",
130
                    "type" => "soft",
131
                    "description" => "Docker: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
132
                ],
133
                "06" => [
134
                    "name" => "Responsive Web Design",
135
                    "type" => "soft",
136
                    "description" => "RWD: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
137
                ],
138
                "07" => [
139
                    "name" => "Adobe XD",
140
                    "type" => "hard",
141
                    "description" => "XD: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut dolor tincidunt, malesuada enim vel, ullamcorper velit. Donec sit amet commodo libero. Curabitur gravida consectetur dolor, eu vulputate ligula aliquam in. Praesent tempus lectus et mauris placerat, nec congue lectus placerat."
142
                ]
143
            ],
144
            "skill_levels" => [
145
                "hard" => [
146
                    "00" => "Beginner",
147
                    "01" => "Intermediate",
148
                    "02" => "Advanced",
149
                    "03" => "Expert"
150
                ],
151
                "soft" => [
152
                    "00" => "In Early Development",
153
                    "01" => "Moderately in Evidence",
154
                    "02" => "Strongly in Evidence",
155
                    "03" => "Deep Level Demonstration"
156
                ]
157
            ]
158
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
159
    }
160
161
    /**
162
     * Create a new resource in storage
163
     * @param  Request $request
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
164
     * @return \Illuminate\Http\Response           A redirect
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
165
     */
166
    public function store(Request $request) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
167
168
        $input = $request->input();
169
170
        $job = new JobPoster();
171
        $job->manager_id = $request->user()->manager->id;
172
        $job->published = ($input['submit'] == 'publish');
173
        $job->fill([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
174
            'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id,
175
            'term_qty' => $input['term_qty'],
176
            'open_date_time' => new Date($input['open_date_time']),
177
            'close_date_time' => new Date($input['close_date_time']),
178
            'start_date_time' => new Date($input['start_date_time']),
179
            'department_id' => $input['department'],
180
            'province_id' => $input['province'],
181
            'salary_min' => $input['salary_min'],
182
            'salary_max' => $input['salary_max'],
183
            'noc' => $input['noc'],
184
            'classification' => $input['classification'],
185
            'security_clearance_id' => $input['security_clearance'],
186
            'language_requirement_id' => $input['language_requirement'],
187
            'en' => [
188
                'city' => $input['city'],
189
                'title' => $input['title']['en'],
190
                'impact' => $input['impact']['en'],
191
                'branch' => $input['branch']['en'],
192
                'division' => $input['division']['en']
193
            ],
194
            'fr' => [
195
                'city' => $input['city'],
196
                'title' => $input['title']['fr'],
197
                'impact' => $input['impact']['fr'],
198
                'branch' => $input['branch']['fr'],
199
                'division' => $input['division']['fr']
200
            ],
201
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
202
        $job->save();
203
204
        if (isset($input['task'])) {
205
            foreach($input['task'] as $task) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
206
                $jobPosterTask = new JobPosterKeyTask();
207
                $jobPosterTask->job_poster_id =  $job->id;
208
                $jobPosterTask->fill([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
209
                    'en' => [
210
                        'description' => $task['en']
211
                    ],
212
                    'fr' => [
213
                        'description' => $task['fr']
214
                    ]
215
                ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
216
                $jobPosterTask->save();
217
            }
218
        }
219
220
        if (isset($input['question'])) {
221
            foreach($input['question'] as $question) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
222
                $jobQuestion = new JobPosterQuestion();
223
                $jobQuestion->job_poster_id = $job->id;
224
                $jobQuestion->fill([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
225
                    'en'=> [
226
                        'question' => $question['question']['en'],
227
                        'description' => $question['description']['en']
228
                    ],
229
                    'fr'=> [
230
                        'question' => $question['question']['fr'],
231
                        'description' => $question['description']['fr']
232
                    ]
233
                ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
234
                $jobQuestion->save();
235
            }
236
        }
237
        return redirect( route('manager.jobs.index') );
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect(route('manager.jobs.index')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
238
    }
239
}
240