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

Fields   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 3 1
A has() 0 3 1
A filled() 0 3 1
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