CommandResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 11 2
A camelCaseToCommand() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of graze/dynamark3-client.
5
 *
6
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://github.com/graze/dynamark3-client/blob/master/LICENSE.md
12
 * @link    https://github.com/graze/dynamark3-client
13
 */
14
15
namespace Graze\Dynamark3Client;
16
17
use \Graze\Dynamark3Client\Command\CommandGeneric;
18
19
class CommandResolver
20
{
21
    /**
22
     * @param string $name
23
     *
24
     * @return \Graze\Dynamark3Client\Command\CommandInterface
25
     */
26 2
    public function resolve($name)
27
    {
28
        // attempt to find a specific command
29 2
        $className = 'Graze\\Dynamark3Client\\Command\\Command' . ucfirst($name);
30 2
        if (class_exists($className)) {
31 1
            return new $className();
32
        }
33
34
        // using the generic command
35 1
        return new CommandGeneric($this->camelCaseToCommand($name));
36
    }
37
38
    /**
39
     * @param string $camelCase
40
     *
41
     * @return string
42
     */
43 1
    protected function camelCaseToCommand($camelCase)
44
    {
45 1
        $parts = preg_split('/(?=[A-Z])/', $camelCase);
46 1
        return strtoupper(implode(' ', $parts));
47
    }
48
}
49