Passed
Push — master ( b8147c...403ced )
by Curtis
11:47 queued 05:39
created

Options::response()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace App\Http\Controllers\enso\companies\Company;
4
5
use App\Models\enso\companies\Company;
6
use Illuminate\Routing\Controller;
7
use LaravelEnso\Select\Traits\OptionsBuilder;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\App;
10
use LaravelEnso\Select\Services\Options as EOptions;
11
use App\Traits\ConnectionTrait;
12
use Auth;
13
class Options extends Controller
14
{
15
    use OptionsBuilder, ConnectionTrait;
0 ignored issues
show
introduced by
The trait LaravelEnso\Select\Traits\OptionsBuilder requires some properties which are not provided by App\Http\Controllers\ens...mpanies\Company\Options: $resource, $appends
Loading history...
16
17
    protected $model = Company::class;
18
19
    protected $queryAttributes = ['name', 'fiscal_code', 'phone'];
20
21
    public function __invoke(Request $request)
22
    {
23
        $conn = $this->getConnection();
24
        if($conn == 'tenant') {
25
            // $companies = Auth::user()->person->companies;
26
            // return $companies;
27
            // $company_ids = [];
28
            // foreach($companies as $item) {
29
            //     array_push($company_ids, $item->id);
30
            // }
31
            // $request->query = $company_ids;
32
        }
33
        return $this->response($request);
34
    }
35
36
    private function response(Request $request)
37
    {
38
        $query = method_exists($this, 'query') ? $this->query($request) : App::make($this->model)::query();
0 ignored issues
show
Bug introduced by
The method query() does not exist on App\Http\Controllers\ens...mpanies\Company\Options. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

38
        $query = method_exists($this, 'query') ? $this->/** @scrutinizer ignore-call */ query($request) : App::make($this->model)::query();
Loading history...
39
40
        return (new EOptions($query))
41
            ->when($request->has('trackBy'), fn ($options) => $options->trackBy($request->get('trackBy')))
42
            ->when($request->has('searchMode'), fn ($options) => $options->searchMode($request->get('searchMode')))
43
            ->when(isset($this->queryAttributes), fn ($options) => $options->queryAttributes($this->queryAttributes))
44
            ->when(isset($this->resource), fn ($options) => $options->resource($this->resource))
0 ignored issues
show
Bug Best Practice introduced by
The property resource does not exist on App\Http\Controllers\ens...mpanies\Company\Options. Did you maybe forget to declare it?
Loading history...
45
            ->when(isset($this->appends), fn ($options) => $options->appends($this->appends));
0 ignored issues
show
Bug Best Practice introduced by
The property appends does not exist on App\Http\Controllers\ens...mpanies\Company\Options. Did you maybe forget to declare it?
Loading history...
46
    }
47
}
48