Completed
Push — master ( bbde24...2d982b )
by Milroy
01:49
created

Sarala   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A resolve() 0 8 2
A getSerializer() 0 4 1
A getSupportedMediaTypes() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sarala;
6
7
class Sarala
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
8
{
9
    private static $instance;
10
11
    private $handlers;
12
13
    private $handler;
14
15
    private $supportedMediaTypes;
16
17
    private 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 static function resolve(): Sarala
31
    {
32
        if (! isset(self::$instance)) {
33
            self::$instance = new Sarala();
34
        }
35
36
        return self::$instance;
37
    }
38
39
    public function getSerializer()
40
    {
41
        return app()->make($this->handler['serializer']);
42
    }
43
44
    public function getSupportedMediaTypes()
45
    {
46
        return $this->supportedMediaTypes;
47
    }
48
}
49