AmplitudeFactory::makeFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
4
namespace LaravelAmplitude;
5
6
use LaravelAmplitude\Drivers\AmplitudeDriverInterface;
7
8
class AmplitudeFactory
9
{
10
    private $driversMap;
11
12
    public function __construct($driversMap)
13
    {
14
        /** @var AmplitudeDriverInterface $driver */
15
        foreach ($driversMap as $driver) {
16
            $this->driversMap[$driver->getDriverName()] = $driver;
17
        }
18
    }
19
20
    public function makeFor($driverName)
21
    {
22
        if (!in_array($driverName, array_keys($this->driversMap))) {
23
            throw new \Exception(sprintf('Driver "%s" not available', $driverName));
24
        }
25
26
        $driver = $this->driversMap[$driverName];
27
        return new Amplitude($driver);
28
    }
29
}
30