AdapterFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 6 1
A getClassName() 0 9 2
1
<?php
2
3
namespace Libcast\AssetDistributor\Adapter;
4
5
use Libcast\AssetDistributor\Owner;
6
use Psr\Log\LoggerInterface;
7
8
class AdapterFactory
9
{
10
    /**
11
     *
12
     * @param string $vendor
13
     * @param Owner  $owner
14
     * @param string $configurationPath
15
     * @return Adapter
16
     * @throws \Exception
17
     */
18
    public static function build($vendor, Owner $owner, $configurationPath, LoggerInterface $logger = null)
19
    {
20
        $class = self::getClassName($vendor);
21
22
        return new $class($owner, $configurationPath, $logger);
23
    }
24
25
    /**
26
     *
27
     * @param string $vendor
28
     * @return string Adapter class name
29
     * @throws \Exception
30
     */
31
    public static function getClassName($vendor)
32
    {
33
        $class = sprintf('\Libcast\AssetDistributor\%1$s\%1$sAdapter', $vendor);
34
        if (!class_exists($class)) {
35
            throw new \Exception("Adapter '$class' does not exists");
36
        }
37
38
        return $class;
39
    }
40
}
41