Completed
Push — master ( 82f2f8...99d29b )
by Milroy
16s queued 10s
created

Sarala   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getSerializer() 0 6 2
A getSupportedMediaTypes() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sarala;
6
7
use League\Fractal\Serializer\DataArraySerializer;
8
9
class Sarala
10
{
11
    private $handlers;
12
13
    private $handler;
14
15
    private $supportedMediaTypes;
16
17
    public function __construct()
18
    {
19
        $this->handlers = collect(config('sarala.handlers'));
20
21
        $this->handler = $this->handlers
22
            ->where('media_type', request()->header('Accept'))
23
            ->first();
24
25
        $this->supportedMediaTypes = $this->handlers
26
            ->pluck('media_type')
27
            ->all();
28
    }
29
30
    public function getSerializer()
31
    {
32
        $serializer = is_null($this->handler) ? DataArraySerializer::class : $this->handler['serializer'];
33
34
        return app()->make($serializer);
35
    }
36
37
    public function getSupportedMediaTypes()
38
    {
39
        return $this->supportedMediaTypes;
40
    }
41
}
42