Passed
Push — main ( 12d5b3...ed8588 )
by Richard
05:00
created

HouseAdController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Furic\HouseAds\Http\Controllers;
4
5
use HouseAd;
0 ignored issues
show
Bug introduced by
The type HouseAd was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Http\Request;
8
9
class HouseAdController extends Controller
10
{
11
12
    /**
13
     * Display a listing of the resource.
14
     *
15
     * @return \Illuminate\Http\Response
16
     */
17
    public function index()
18
    {
19
        return HouseAd::whereDate('start_at', '<=', date('Y-m-d'))->whereDate('end_at', '>=', date('Y-m-d'))->get();
20
    }
21
22
    /**
23
     * Display the specified resource.
24
     *
25
     * @param  int  $id
26
     * @return \Illuminate\Http\Response
27
     */
28
    public function show($id)
29
    {
30
        return HouseAd::findOrFail($id);
31
    }
32
33
    /**
34
     * Update the specified resource in storage.
35
     *
36
     * @param  Request  $request
37
     * @param  int  $id
38
     * @return \Illuminate\Http\Response
39
     */
40
    public function update(Request $request, $id)
41
    {
42
        $this->validate($request, ['confirmed' => 'required|numeric']);
43
44
        $houseAd = HouseAd::findOrFail($id);
45
46
        // A check to prevent hacker to change the level owner
47
        if ($request->confirmed == '1')
48
            $houseAd->confirmed_count++;
49
        else
50
            $houseAd->cancelled_count++;
51
52
        $houseAd->save();
53
54
        return $houseAd;
55
    }
56
57
}
58