AmplitudeFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A makeFor() 0 9 2
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