SickController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 0
cbo 5
dl 0
loc 120
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 5 1
A create() 0 5 1
B store() 0 38 2
A show() 0 5 1
A edit() 0 4 1
A update() 0 4 1
A destroy() 0 4 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Http\Requests;
7
use App\Sick;
8
use App\User;
9
10
class SickController extends Controller
11
{
12
    public function __construct()
13
    {
14
        $this->middleware('auth');
15
    }
16
17
    /**
18
     * Display a listing of the resource.
19
     *
20
     * @return \Illuminate\Http\Response
21
     */
22
    public function index()
23
    {
24
        $adata = sick::All();
25
        return view('sick/home', ['adata' => $adata]);
26
    }
27
28
    /**
29
     * Show the form for creating a new resource.
30
     *
31
     * @return \Illuminate\Http\Response
32
     */
33
    public function create()
34
    {
35
        $users = User::All();
36
        return view('sick/register', ['users' => $users]);
37
    }
38
39
    /**
40
     * Store a newly created resource in storage.
41
     *
42
     * @param  \Illuminate\Http\Request $request
43
     * @return \Illuminate\Http\Response
44
     */
45
    public function store(Request $request)
46
    {
47
        $this->validate($request, [
48
            'type' => 'required',
49
            'start_date' => 'required',
50
            'stop_date' => 'required',
51
            'employee' => 'required',
52
        ]);
53
54
        $matchThese = ['user_id' => $request->get('employee'), 'start_date' => $request->get('start_date')];
55
        $verify = sick::where($matchThese)->first();
56
        if ($verify === null) {
57
            // user doesn't exist
58
59
            $data = new sick;
60
            $data->type = $request->get('type');
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<App\Sick>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
            $data->start_date = $request->get('start_date');
0 ignored issues
show
Documentation introduced by
The property start_date does not exist on object<App\Sick>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
            $data->end_date = $request->get('stop_date');
0 ignored issues
show
Documentation introduced by
The property end_date does not exist on object<App\Sick>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
63
            $data->user_id = $request->get('employee');
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<App\Sick>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64
            $data->description = $request->get('description');
0 ignored issues
show
Documentation introduced by
The property description does not exist on object<App\Sick>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
            $data->save();
66
67
            $user_id = $request->get('employee');
0 ignored issues
show
Unused Code introduced by
$user_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
            $subject = \Lang::get('tasks.new_sick_notification');
69
            $mailbox = env('MAIL_USERNAME');
70
71
            \Session::flash('message', "Information has been saved to the database");
72
            \Mail::send('emails.new_sick', ['data' => $data], function ($m) use ($mailbox, $subject) {
73
                $m->from($mailbox);
74
                $m->to("[email protected]")->subject("$subject");
75
            });
76
77
            return redirect('sick');
78
        } else {
79
            \Session::flash('error', "This data has already been saved");
80
            return redirect('sick');
81
        }
82
    }
83
84
    /**
85
     * Display the specified resource.
86
     *
87
     * @param  int $id
88
     * @return \Illuminate\Http\Response
89
     */
90
    public function show($id)
91
    {
92
        $data = sick::findOrFail($id);
93
        return view('sick/info', ['data' => $data, 'data_id' => $id]);
94
    }
95
96
    /**
97
     * Show the form for editing the specified resource.
98
     *
99
     * @param  int $id
100
     * @return \Illuminate\Http\Response
101
     */
102
    public function edit($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103
    {
104
        //
105
    }
106
107
    /**
108
     * Update the specified resource in storage.
109
     *
110
     * @param  \Illuminate\Http\Request $request
111
     * @param  int $id
112
     * @return \Illuminate\Http\Response
113
     */
114
    public function update(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
115
    {
116
        //
117
    }
118
119
    /**
120
     * Remove the specified resource from storage.
121
     *
122
     * @param  int $id
123
     * @return \Illuminate\Http\Response
124
     */
125
    public function destroy($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
126
    {
127
        //
128
    }
129
}
130