Sarala::getSupportedMediaTypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sarala;
6
7
use Illuminate\Support\Collection;
8
use League\Fractal\Serializer\DataArraySerializer;
9
10
class Sarala
11
{
12
    private Collection $handlers;
13
14
    private $handler;
15
16
    private array $supportedMediaTypes;
17
18
    public function __construct()
19
    {
20
        $this->handlers = collect(config('sarala.handlers'));
21
22
        $this->handler = $this->handlers
23
            ->where('media_type', request()->header('Accept'))
24
            ->first();
25
26
        $this->supportedMediaTypes = $this->handlers
27
            ->pluck('media_type')
28
            ->all();
29
    }
30
31
    public function getSerializer()
32
    {
33
        $serializer = is_null($this->handler) ? DataArraySerializer::class : $this->handler['serializer'];
34
35
        return resolve($serializer);
36
    }
37
38
    public function getSupportedMediaTypes(): array
39
    {
40
        return $this->supportedMediaTypes;
41
    }
42
}
43