BaseRouter   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 0

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 85
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A shortName() 0 7 1
A addExtension() 0 4 1
A path() 0 4 2
A exists() 0 6 2
A getPath() 0 4 1
A getExtension() 0 8 2
1
<?php
2
3
namespace League\CLImate\TerminalObject\Router;
4
5
abstract class BaseRouter implements RouterInterface
6
{
7
    protected $extensions = [];
8
9
    /**
10
     * Add a custom extension to CLImate
11
     *
12
     * @param string $key
13
     * @param string $class
14
     */
15 28
    public function addExtension($key, $class)
16
    {
17 28
        $this->extensions[$key] = $class;
18 28
    }
19
20
    /**
21
     * Get the full path for the class based on the key
22
     *
23
     * @param string $class
24
     *
25
     * @return string
26
     */
27 576
    public function path($class)
28
    {
29 576
        return $this->getExtension($class) ?: $this->getPath($this->shortName($class));
30
    }
31
32
    /**
33
     * Determines if the requested class is a
34
     * valid terminal object class
35
     *
36
     * @param  string  $class
37
     *
38
     * @return boolean
39
     */
40 576
    public function exists($class)
41
    {
42 576
        $class = $this->path($class);
43
44 576
        return (is_object($class) || class_exists($class));
45
    }
46
47
    /**
48
     * Get the full path for the terminal object class
49
     *
50
     * @param  string $class
51
     *
52
     * @return string
53
     */
54 560
    protected function getPath($class)
55
    {
56 560
        return 'League\CLImate\TerminalObject\\' . $this->pathPrefix() . '\\' . $class;
57
    }
58
59
    /**
60
     * Get an extension by its key
61
     *
62
     * @param string $key
63
     *
64
     * @return string|false Full class path to extension
65
     */
66 576
    protected function getExtension($key)
67
    {
68 576
        if (array_key_exists($key, $this->extensions)) {
69 28
            return $this->extensions[$key];
70
        }
71
72 560
        return false;
73
    }
74
75
    /**
76
     * Get the class short name
77
     *
78
     * @param string $name
79
     *
80
     * @return string
81
     */
82 560
    protected function shortName($name)
83
    {
84 560
        $name = str_replace('_', ' ', $name);
85 560
        $name = ucwords($name);
86
87 560
        return str_replace(' ', '', $name);
88
    }
89
}
90