SourcesController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 5 1
A list() 0 11 2
A __construct() 0 3 1
A delete() 0 5 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\SourceCreateRequest;
6
use App\Http\Resources\SourceResource;
7
use App\Models\Source;
8
use App\Services\TenantManager;
9
use App\Utils\SourceCreator;
10
use Illuminate\Http\Request;
11
12
class SourcesController extends Controller
13
{
14
    /**
15
     * Create a new controller instance.
16
     *
17
     * @param TenantManager $tenantManager
18
     *
19
     * @return void
20
     */
21
    public function __construct(TenantManager $tenantManager)
22
    {
23
        SourceResource::setTenantManager($tenantManager); //workaround - not the best but it works well
24
    }
25
26
    public function list(Request $request)
27
    {
28
        $recruitmentId = $request->get('recruitment_id');
0 ignored issues
show
Bug introduced by
The method get() does not exist on Illuminate\Http\Request. ( Ignorable by Annotation )

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

28
        /** @scrutinizer ignore-call */ 
29
        $recruitmentId = $request->get('recruitment_id');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
30
        if ($recruitmentId) {
31
            $sources = Source::where('recruitment_id', $recruitmentId)->orderBy('created_at', 'DESC')->get();
32
        } else {
33
            $sources = Source::orderBy('created_at', 'DESC')->get();
34
        }
35
36
        return SourceResource::collection($sources);
37
    }
38
39
    public function create(SourceCreateRequest $request)
40
    {
41
        $source = SourceCreator::create($request->validated());
42
43
        return new SourceResource($source);
44
    }
45
46
    public function delete($sourceId)
47
    {
48
        Source::find($sourceId)->delete();
49
50
        return response()->json(null, 200);
51
    }
52
}
53