Issues (465)

app/Http/Controllers/PersonController.php (59 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Person;
6
use Illuminate\Http\Request;
7
8
class PersonController extends Controller
9
{
10
    /**
11
     * Display a listing of the resource.
12
     *
13
     * @return \Illuminate\Http\Response
14
     */
15
    public function index(Request $request)
16
    {
17
        $query = Person::query();
18
19
        if ($request->has('searchTerm')) {
20
            $columnsToSearch = ['title', 'name', 'appellative', 'uid', 'email', 'phone', 'birthday', 'deathday', 'bank', 'bank_account', 'obs', 'givn', 'surn', 'type', 'npfx', 'nick', 'spfx', 'nsfx', 'secx', 'description', 'child_in_family_id', 'chan', 'rin', 'resn', 'rfn', 'afn'];
21
            $search_term = json_decode($request->searchTerm)->searchTerm;
22
            if (! empty($search_term)) {
23
                $searchQuery = '%'.$search_term.'%';
24
                foreach ($columnsToSearch as $column) {
25
                    $query->orWhere($column, 'LIKE', $searchQuery);
26
                }
27
            }
28
        }
29
30
        if ($request->has('columnFilters')) {
31
            $filters = get_object_vars(json_decode($request->columnFilters));
32
33
            foreach ($filters as $key => $value) {
34
                if (! empty($value)) {
35
                    $query->orWhere($key, 'like', '%'.$value.'%');
36
                }
37
            }
38
        }
39
40
        if ($request->has('sort.0')) {
41
            $sort = json_decode($request->sort[0]);
42
            $query->orderBy($sort->field, $sort->type);
43
        }
44
45
        if ($request->has('perPage')) {
46
            $rows = $query->paginate($request->perPage);
47
        }
48
        if (! count($request->all())) {
49
            $rows = $query->get()->toArray();
50
        }
51
52
        return $rows;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rows does not seem to be defined for all execution paths leading up to this point.
Loading history...
53
    }
54
55
    /**
56
     * Show the form for creating a new resource.
57
     *
58
     * @return \Illuminate\Http\Response
59
     */
60
    public function create()
61
    {
62
        //
63
    }
64
65
    /**
66
     * Store a newly created resource in storage.
67
     *
68
     * @param  \Illuminate\Http\Request  $request
69
     * @return \Illuminate\Http\Response
70
     */
71
    public function store(Request $request)
72
    {
73
        $request->validate([
74
            'name' => 'required',
75
        ]);
76
77
        $person = new Person();
78
        $person->title = $request->title;
0 ignored issues
show
The property title does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
79
        $person->name = $request->name;
0 ignored issues
show
The property name does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
80
        $person->appellative = $request->appellative;
0 ignored issues
show
The property appellative does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
81
        $person->uid = $request->uid;
0 ignored issues
show
The property uid does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
82
        $person->email = $request->email;
0 ignored issues
show
The property email does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
83
        $person->phone = $request->phone;
0 ignored issues
show
The property phone does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
84
        $person->birthday = $request->birthday;
0 ignored issues
show
The property birthday does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
85
        $person->deathday = $request->deathday;
0 ignored issues
show
The property deathday does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
86
        $person->bank = $request->bank;
0 ignored issues
show
The property bank does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
87
        $person->bank_account = $request->bank_account;
0 ignored issues
show
The property bank_account does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
88
        $person->obs = $request->obs;
0 ignored issues
show
The property obs does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
89
        $person->givn = $request->givn;
0 ignored issues
show
The property givn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
90
        $person->surn = $request->surn;
0 ignored issues
show
The property surn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
91
        $person->type = $request->type;
0 ignored issues
show
The property type does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
92
        $person->npfx = $request->npfx;
0 ignored issues
show
The property npfx does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
93
        $person->nick = $request->nick;
0 ignored issues
show
The property nick does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
94
        $person->spfx = $request->spfx;
0 ignored issues
show
The property spfx does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
95
        $person->nsfx = $request->nsfx;
0 ignored issues
show
The property nsfx does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
96
        $person->sex = $request->sex;
0 ignored issues
show
The property sex does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
97
        $person->description = $request->description;
0 ignored issues
show
The property description does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
98
        $person->child_in_family_id = $request->child_in_family_id;
0 ignored issues
show
The property child_in_family_id does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
99
        $person->chan = $request->chan;
0 ignored issues
show
The property chan does not exist on App\Models\Person. Did you mean changes?
Loading history...
100
        $person->rin = $request->rin;
0 ignored issues
show
The property rin does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
101
        $person->resn = $request->resn;
0 ignored issues
show
The property resn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
102
        $person->rfn = $request->rfn;
0 ignored issues
show
The property rfn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
103
        $person->afn = $request->afn;
0 ignored issues
show
The property afn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
104
        $person->save();
105
106
        return $person;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $person returns the type App\Models\Person which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
107
    }
108
109
    /**
110
     * Display the specified resource.
111
     *
112
     * @param  int  $id
113
     * @return \Illuminate\Http\Response
114
     */
115
    public function show($id)
116
    {
117
        return Person::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Person::find($id) also could return the type App\Models\Person which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
118
    }
119
120
    /**
121
     * Show the form for editing the specified resource.
122
     *
123
     * @param  int  $id
124
     * @return \Illuminate\Http\Response
125
     */
126
    public function edit($id)
0 ignored issues
show
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

126
    public function edit(/** @scrutinizer ignore-unused */ $id)

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

Loading history...
127
    {
128
        //
129
    }
130
131
    /**
132
     * Update the specified resource in storage.
133
     *
134
     * @param  \Illuminate\Http\Request  $request
135
     * @param  int  $id
136
     * @return \Illuminate\Http\Response
137
     */
138
    public function update(Request $request, $id)
139
    {
140
        $request->validate([
141
            'name' => 'required',
142
        ]);
143
144
        $person = Person::find($id);
145
        $person->title = $request->title;
0 ignored issues
show
The property title does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
146
        $person->name = $request->name;
0 ignored issues
show
The property name does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
147
        $person->appellative = $request->appellative;
0 ignored issues
show
The property appellative does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
148
        $person->uid = $request->uid;
0 ignored issues
show
The property uid does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
149
        $person->email = $request->email;
0 ignored issues
show
The property email does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
150
        $person->phone = $request->phone;
0 ignored issues
show
The property phone does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
151
        $person->birthday = $request->birthday;
0 ignored issues
show
The property birthday does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
152
        $person->deathday = $request->deathday;
0 ignored issues
show
The property deathday does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
153
        $person->bank = $request->bank;
0 ignored issues
show
The property bank does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
154
        $person->bank_account = $request->bank_account;
0 ignored issues
show
The property bank_account does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
155
        $person->obs = $request->obs;
0 ignored issues
show
The property obs does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
156
        $person->givn = $request->givn;
0 ignored issues
show
The property givn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
157
        $person->surn = $request->surn;
0 ignored issues
show
The property surn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
158
        $person->type = $request->type;
0 ignored issues
show
The property type does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
159
        $person->npfx = $request->npfx;
0 ignored issues
show
The property npfx does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
160
        $person->nick = $request->nick;
0 ignored issues
show
The property nick does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
161
        $person->spfx = $request->spfx;
0 ignored issues
show
The property spfx does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
162
        $person->nsfx = $request->nsfx;
0 ignored issues
show
The property nsfx does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
163
        $person->sex = $request->sex;
0 ignored issues
show
The property sex does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
164
        $person->description = $request->description;
0 ignored issues
show
The property description does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
165
        $person->child_in_family_id = $request->child_in_family_id;
0 ignored issues
show
The property child_in_family_id does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
166
        $person->chan = $request->chan;
0 ignored issues
show
The property chan does not exist on App\Models\Person. Did you mean changes?
Loading history...
167
        $person->rin = $request->rin;
0 ignored issues
show
The property rin does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
168
        $person->resn = $request->resn;
0 ignored issues
show
The property resn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
169
        $person->rfn = $request->rfn;
0 ignored issues
show
The property rfn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
170
        $person->afn = $request->afn;
0 ignored issues
show
The property afn does not seem to exist on App\Models\Person. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
171
        $person->save();
172
173
        return $person;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $person also could return the type App\Models\Person which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
174
    }
175
176
    /**
177
     * Remove the specified resource from storage.
178
     *
179
     * @param  int  $id
180
     * @return \Illuminate\Http\Response
181
     */
182
    public function destroy($id)
183
    {
184
        $person = Person::find($id);
185
        if ($person) {
186
            $person->delete();
187
188
            return 'true';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'true' returns the type string which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
189
        }
190
191
        return 'false';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'false' returns the type string which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
192
    }
193
}
194