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

Sarala::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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