Completed
Push — master ( b68b20...ae6559 )
by Milroy
02:48
created

Fields::filled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiChef\RequestQueryHelper;
6
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Collection;
9
10
class Fields
11
{
12
    /** @var Collection $fields */
13
    private $fields;
14
15 12
    public function __construct(Request $request)
16
    {
17 12
        $this->fields = collect($request->get(config('request-query-helper.fields'), []))
18
            ->mapWithKeys(function ($value, $key) {
19 12
                return [$key => explode(',', $value)];
20 12
            });
21 12
    }
22
23 6
    public function has($resourceName)
24
    {
25 6
        return $this->fields->has($resourceName);
26
    }
27
28 6
    public function get(string $resourceName): array
29
    {
30 6
        return $this->fields->get($resourceName, []);
31
    }
32
33 3
    public function filled(): bool
34
    {
35 3
        return $this->fields->isNotEmpty();
36
    }
37
}
38