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

DropletFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 32
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B getDroplet() 0 24 8
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