FirebaseProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Piotzkhider\FirebaseModule;
6
7
use Kreait\Firebase;
8
use Kreait\Firebase\Factory;
9
use Kreait\Firebase\ServiceAccount;
10
use Piotzkhider\FirebaseModule\Annotation\Credentials;
11
use Ray\Di\Di\PostConstruct;
12
use Ray\Di\ProviderInterface;
13
14
class FirebaseProvider implements ProviderInterface
15
{
16
    /**
17
     * @var mixed
18
     */
19
    private $credentials;
20
21
    /**
22
     * @var Firebase
23
     */
24
    private $firebase;
25
26
    /**
27
     * @Credentials()
28
     */
29 5
    public function __construct($credentials)
30
    {
31 5
        $this->credentials = $credentials;
32 5
    }
33
34
    /**
35
     * @PostConstruct
36
     */
37 5
    public function init(): void
38
    {
39 5
        $serviceAccount = ServiceAccount::fromValue($this->credentials);
40
41 5
        $this->firebase = (new Factory())
42 5
            ->withServiceAccount($serviceAccount)
43 5
            ->create();
44 5
    }
45
46 5
    public function get()
47
    {
48 5
        return $this->firebase;
49
    }
50
}
51