Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 40
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canCreate() 0 4 1
A create() 0 10 2
A getFullPath() 0 6 1
1
<?php
2
3
namespace BigShark\SQLToBuilder\Converter;
4
5
class Factory
6
{
7
    /**
8
     * @param string $key
9
     *
10
     * @return bool
11
     */
12 102
    public function canCreate($key)
13
    {
14 102
        return class_exists($this->getFullPath($key));
15
    }
16
17
    /**
18
     * @param string $key
19
     *
20
     * @return ConverterInterface
21
     */
22 99
    public function create($key)
23
    {
24 99
        if ($this->canCreate($key)) {
25 99
            $class = $this->getFullPath($key);
26
27 99
            return new $class();
28
        } else {
29 3
            throw new \InvalidArgumentException("{$key} converter not found");
30
        }
31
    }
32
33
    /**
34
     * @param string $key
35
     *
36
     * @return string
37
     */
38 102
    protected function getFullPath($key)
39
    {
40 102
        $key = ucfirst(strtolower($key));
41
42 102
        return 'BigShark\\SQLToBuilder\\Converter\\'.$key.'Converter';
43
    }
44
}
45