TimelogController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A store() 0 16 3
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Project;
6
use Illuminate\Http\Request;
7
use App\Http\Controllers\Controller;
8
9
class TimelogController extends Controller
10
{
11
    public function __construct()
12
    {
13
        return $this->middleware('auth');
14
    }
15
    
16
    /**
17
     * Store a time log for a project
18
     *
19
     * @param \Illuminate\Http\Request $request
20
     * @param \App\Project $project
21
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\Routing\ResponseFactory
22
     */
23
    public function store(Request $request, Project $project)
24
    {
25
        if (!auth()->user()->can('update', $project)) {
26
            return redirect()->route('home');
27
        }
28
29
        $timelog = $project->timelogs()->create([
30
            'user_id' => $request->user()->id,
31
            'number_of_seconds' => $request->number_of_seconds
32
        ]);
33
        
34
        if ($request->expectsJson()) {
35
            return response(['success' => true, 'project' => $project, 'timelog' => $timelog], 201);
0 ignored issues
show
Bug introduced by
array('success' => true,... 'timelog' => $timelog) of type array<string,mixed|true|App\Project> is incompatible with the type string expected by parameter $content of response(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            return response(/** @scrutinizer ignore-type */ ['success' => true, 'project' => $project, 'timelog' => $timelog], 201);
Loading history...
36
        }
37
38
        return redirect()->route('projects.show', [$project]);
39
    }
40
41
}
42