Completed
Push — master ( 9d56e7...43a437 )
by Prabath
10:19 queued 08:51
created

SocialFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 27
ccs 8
cts 9
cp 0.8889
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdapterClassname() 0 5 1
A create() 0 6 2
1
<?php
2
3
4
namespace databoxtech\multisocial;
5
6
7
use databoxtech\multisocial\adapter\SocialAdapter;
8
9
class SocialFactory
10
{
11
12
    /**
13
     * Create a new instance of social adapter
14
     *
15
     * @param string $name $name
16
     * @param array $config
17
     * @return SocialAdapter
18
     */
19 2
    public function create(string $name, array $config){
20 2
        $class = $this->getAdapterClassname($name);
21 2
        if (!class_exists($class)) {
22
            throw new \RuntimeException("Class '$class' not found");
23
        }
24 2
        return new $class($config);
25
    }
26
27
    /**
28
     * @param string $name adapter name
29
     * @return string PSR-0 classpath
30
     */
31 2
    private function getAdapterClassname(string $name){
32 2
        $name = ucfirst($name);
33
        // replace underscores with namespace marker, PSR-0 style
34 2
        $name = str_replace('_', '\\', $name);
35 2
        return '\\databoxtech\\multisocial\\adapter\\'.$name.'Adapter';
36
    }
37
}