Completed
Push — develop ( 58742c...7889c1 )
by Mohamed
03:32
created

Controller::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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\Http\Controllers;
13
14
use Illuminate\Foundation\Bus\DispatchesJobs;
15
use Illuminate\Routing\Controller as BaseController;
16
use Illuminate\Foundation\Validation\ValidatesRequests;
17
use Illuminate\Contracts\Auth\Guard;
18
use Tinyissue\Model;
19
20
/**
21
 * Controller is an abstract class for the controller classes.
22
 *
23
 * @author Mohamed Alsharaf <[email protected]>
24
 */
25
abstract class Controller extends BaseController
26
{
27
    use DispatchesJobs, ValidatesRequests;
28
29
    /**
30
     * Current logged in user.
31
     *
32
     * @var Guard
33
     */
34
    protected $auth;
35
36
    /**
37
     * Constructor, inject an instance of logged user.
38
     *
39
     * @param \Illuminate\Contracts\Auth\Guard $auth
40
     */
41 58
    public function __construct(Guard $auth)
42
    {
43 58
        $this->auth = $auth;
44 58
    }
45
46
    /**
47
     * Return instance of the logged user.
48
     *
49
     * @return Model\User
50
     */
51
    protected function getLoggedUser()
52
    {
53
        $user = $this->getLoggedUser();
54
55
        if (!$user instanceof Model\User) {
56
            $user =  new Model\User();
57
        }
58
59
        return $user;
60
    }
61
}
62