Issues (465)

app/Http/Controllers/DashboardController.php (10 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Company;
6
use App\Models\Family;
7
use App\Models\Person;
8
use App\Models\Tree;
9
use App\Models\User;
10
use Carbon\Carbon;
11
use Illuminate\Http\Request;
12
13
class DashboardController extends Controller
14
{
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index(Request $request)
0 ignored issues
show
The parameter $request 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

20
    public function index(/** @scrutinizer ignore-unused */ Request $request)

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...
21
    {
22
        $male = Person::where('sex', 'M')->get()->count();
23
        $female = Person::where('sex', 'F')->get()->count();
24
        $unknown = Person::whereNull('sex')->get()->count();
25
        $familiesjoined = Family::all()->count();
26
        $peoplesattached = Person::all()->count();
27
        $chart = [$male, $female, $unknown];
28
29
        return ['chart' => $chart, 'familiesjoined' => $familiesjoined, 'peoplesattached' => $peoplesattached];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('chart' => ...d' => $peoplesattached) returns the type array<string,array<integer,integer>|integer> which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return \Illuminate\Http\Response
36
     */
37
    public function create()
38
    {
39
        $user = auth()->user();
40
        $company = $user->Company();
41
        $trees = Tree::where('company_id', $company->id)->get();
42
43
        return $trees;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $trees returns the type Illuminate\Database\Eloquent\Collection which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
44
    }
45
46
    public function getCompany()
47
    {
48
        $user = auth()->user();
49
        $company = $user->Company;
50
51
        return $company;
52
    }
53
54
    public function getTree()
55
    {
56
        $trees = Tree::where('company_id', request('company_id'))->get();
57
58
        return $trees;
59
    }
60
61
    public function changedb(Request $request)
62
    {
63
        $company_id = $request->get('company_id');
64
        $tree_id = $request->get('tree_id');
65
        if (! empty($company_id) && ! empty($tree_id)) {
66
            $user = auth()->user();
67
            $companies_id = $user->Company()->pluck('companies.id');
68
            $company = $user->Company()->update([
0 ignored issues
show
The assignment to $company is dead and can be removed.
Loading history...
69
                'current_tenant'=> 0,
70
            ]);
71
            $company = Company::find($company_id);
72
            $company->current_tenant = 1;
73
            $company->save();
74
            Tree::whereIn('company_id', $companies_id)->update(['current_tenant' => 0]);
75
            $tree = Tree::find($tree_id);
76
            $tree->current_tenant = 1;
77
            $tree->save();
78
79
            return response()->json(['changedb' => true]);
80
        } else {
81
            return response()->json(['changedb' => false]);
82
        }
83
    }
84
85
    /**
86
     * Store a newly created resource in storage.
87
     *
88
     * @param  \Illuminate\Http\Request  $request
89
     * @return \Illuminate\Http\Response
90
     */
91
    public function store(Request $request)
0 ignored issues
show
The parameter $request 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

91
    public function store(/** @scrutinizer ignore-unused */ Request $request)

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...
92
    {
93
    }
94
95
    /**
96
     * Display the specified resource.
97
     *
98
     * @param  int  $id
99
     * @return \Illuminate\Http\Response
100
     */
101
    public function show($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

101
    public function show(/** @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...
102
    {
103
    }
104
105
    /**
106
     * Show the form for editing the specified resource.
107
     *
108
     * @param  int  $id
109
     * @return \Illuminate\Http\Response
110
     */
111
    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

111
    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...
112
    {
113
        //
114
    }
115
116
    /**
117
     * Update the specified resource in storage.
118
     *
119
     * @param  \Illuminate\Http\Request  $request
120
     * @param  int  $id
121
     * @return \Illuminate\Http\Response
122
     */
123
    public function update(Request $request, $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

123
    public function update(Request $request, /** @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...
The parameter $request 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

123
    public function update(/** @scrutinizer ignore-unused */ Request $request, $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...
124
    {
125
    }
126
127
    /**
128
     * Remove the specified resource from storage.
129
     *
130
     * @param  int  $id
131
     * @return \Illuminate\Http\Response
132
     */
133
    public function destroy($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

133
    public function destroy(/** @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...
134
    {
135
    }
136
137
    public function trial()
138
    {
139
        $user = auth()->user();
140
        if ($user->subscribed('default')) {
141
            $days = Carbon::now()->diffInDays(Carbon::parse($user->subscription('default')->asStripeSubscription()->current_period_end));
142
        } else {
143
            $days = Carbon::now()->diffInDays($user->trial_ends_at);
144
        }
145
146
        return ['days' => $days];
147
    }
148
}
149