Factory::canCreate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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