Passed
Push — develop ( fdb96a...bba4e3 )
by Niclas Leon
04:22
created

ShareController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Hacktoberfest\GitHub\PullRequestChecker;
6
use App\User;
7
8
class ShareController extends Controller
9
{
10
    /**
11
     * Instance of the 'pull request checker'.
12
     *
13
     * @var PullRequestChecker
14
     */
15
    protected $checker;
16
17
    /**
18
     * Instance of user model.
19
     *
20
     * @var User
21
     */
22
    protected $user;
23
24
25
    /**
26
     * Create a new controller instance.
27
     *
28
     * @param PullRequestChecker $checker
29
     */
30
    public function __construct(PullRequestChecker $checker, User $user)
31
    {
32
        $this->checker     = $checker;
33
        $this->user        = $user;
34
        $this->sharingMode = true;
35
36
        parent::__construct();
37
    }
38
39
    /**
40
     * Display a user's PR status if user already authorized this app,
41
     * otherwise redirect to home page.
42
     *
43
     * @param string $github_username
44
     *
45
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
46
     */
47
    public function index($github_username)
48
    {
49
        $user = $this->user->where('github_username', '=', $github_username)->first();
50
51
        if (!$user) {
52
            return redirect('/');
53
        }
54
55
        $prs = $this->checker->getQualifiedPullRequests($user);
56
57
        $viewData = compact('user', 'prs');
58
        $viewData['sharingMode'] = $this->sharingMode;
59
60
        return view('status', $viewData);
61
    }
62
}
63