Sarala   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
dl 0
loc 31
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSerializer() 0 5 2
A __construct() 0 11 1
A getSupportedMediaTypes() 0 3 1
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