Completed
Branch master (ae6db9)
by Matt
01:40
created

DropletFactory::getDroplet()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 17
nc 8
nop 1
dl 0
loc 24
ccs 18
cts 18
cp 1
crap 8
rs 8.4444
c 0
b 0
f 0
1
<?php
2
namespace Billow\Droplets;
3
use InvalidArgumentException;
4
use RuntimeException;
5
6
/**
7
 * @author Matt Frost<[email protected]>
8
 * @package Billow
9
 * @subpackage Droplets
10
 * @license http://opensource.org/licenses/MIT MIT
11
 */
12
class DropletFactory implements DropletFactoryInterface
13
{
14
    /**
15
     * Method to retrieve the proper type of Droplet based on parameter
16
     *
17
     * @param Array $dropletInfo 
18
     * @return \Billow\Droplets\DropletInterface
19
     */
20 12
    public function getDroplet(Array $dropletInfo)
21
    {
22 12
        if (!isset($dropletInfo['image']['distribution'])) {
23 2
            throw new InvalidArgumentException('Image information not found in droplet info');
24
        }
25
26 10
        $image = $dropletInfo['image']['distribution'];
27
28 10
        switch (strtolower($image)) {
29 10
            case 'ubuntu':
30 4
                return new Ubuntu($dropletInfo);
31 6
            case 'fedora':
32 1
                return new Fedora($dropletInfo);
33 5
            case 'debian':
34 1
                return new Debian($dropletInfo);
35 4
            case 'centos':
36 1
                return new CentOS($dropletInfo);
37 3
            case 'coreos':
38 1
                return new CoreOS($dropletInfo);
39 2
            case 'freebsd':
40 1
                return new FreeBSD($dropletInfo);
41
        }
42
43 1
        throw new RuntimeException('There is no droplet matching the image provided in the droplet info');
44
    }
45
}
46