TodoBarProjects::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
nc 1
nop 0
dl 0
loc 4
c 1
b 0
f 1
cc 1
rs 10
1
<?php
2
3
namespace TPaksu\TodoBar\Controllers;
4
5
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...
6
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request 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 TPaksu\TodoBar\Storage\DataStorageInterface;
8
9
class TodoBarProjects extends Controller
10
{
11
12
    protected $storage;
13
14
    public function __construct(DataStorageInterface $storage)
15
    {
16
        $this->storage = $storage;
17
    }
18
    /**
19
     * Display a listing of the resource.
20
     *
21
     * @return \Illuminate\Http\Response
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Response 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...
22
     */
23
    public function index()
24
    {
25
        $data = collect($this->storage->all())->pluck("name");
0 ignored issues
show
Bug introduced by
The function collect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

25
        $data = /** @scrutinizer ignore-call */ collect($this->storage->all())->pluck("name");
Loading history...
26
        return response()->json(["status" => "success", "data" => $data], 200);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

26
        return /** @scrutinizer ignore-call */ response()->json(["status" => "success", "data" => $data], 200);
Loading history...
27
    }
28
29
    /**
30
     * Store a newly created resource in storage.
31
     *
32
     * @param  \Illuminate\Http\Request  $request
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function store(Request $request)
36
    {
37
        $new_id = $this->storage->insert([
38
            "name" => $request->name,
39
            "tasks" => []
40
        ]);
41
        return response()->json(["status" => "success", "id" => $new_id, "name" => $request->name], 200);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

41
        return /** @scrutinizer ignore-call */ response()->json(["status" => "success", "id" => $new_id, "name" => $request->name], 200);
Loading history...
42
43
    }
44
45
    /**
46
     * Display the specified resource.
47
     *
48
     * @param  int  $id
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function show($id)
52
    {
53
        $tasks = $this->storage->find($id) ?? [];
54
        return response()->json(["status" => "success", "tasks" => $tasks], 200);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

54
        return /** @scrutinizer ignore-call */ response()->json(["status" => "success", "tasks" => $tasks], 200);
Loading history...
55
    }
56
57
    /**
58
     * Update the specified resource in storage.
59
     *
60
     * @param  \Illuminate\Http\Request  $request
61
     * @param  int  $id
62
     * @return \Illuminate\Http\Response
63
     */
64
    public function update(Request $request, $id)
65
    {
66
        $this->storage->update($id, [
67
            "name" => $request->name,
68
        ]);
69
        return response()->json(["status" => "success", "id" => $id, "name" => $request->name], 200);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

69
        return /** @scrutinizer ignore-call */ response()->json(["status" => "success", "id" => $id, "name" => $request->name], 200);
Loading history...
70
    }
71
72
    /**
73
     * Remove the specified resource from storage.
74
     *
75
     * @param  int  $id
76
     * @return \Illuminate\Http\Response
77
     */
78
    public function destroy($id)
79
    {
80
        $this->storage->delete($id);
81
        return response()->json(["status" => "success"], 200);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

81
        return /** @scrutinizer ignore-call */ response()->json(["status" => "success"], 200);
Loading history...
82
    }
83
}
84