StandardNameResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 61
ccs 0
cts 28
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getNameFromClass() 0 11 1
A getClassFromName() 0 6 1
A getClassNameFromFile() 0 6 1
1
<?php
2
3
  namespace Funivan\Console\NameResolver;
4
5
  /**
6
   * @author Ivan Shcherbak <[email protected]>
7
   */
8
  class StandardNameResolver implements NameResolverInterface {
9
10
    /**
11
     * @var string
12
     */
13
    private $namespace;
14
15
16
    /**
17
     * @param string $namespace
18
     * @throws \InvalidArgumentException
19
     */
20
    public function __construct($namespace) {
21
      if (!is_string($namespace)) {
22
        throw new \InvalidArgumentException('Namespace should be string');
23
      }
24
      $this->namespace = '\\' . trim($namespace, '\\') . '\\';
25
    }
26
27
28
    /**
29
     * @param string $class
30
     * @return string
31
     */
32
    public function getNameFromClass($class) {
33
      return implode(':',
34
        array_map(
35
          'lcfirst',
36
          array_slice(explode(
37
            '\\',
38
            trim($class, '\\')
39
          ), 1)
40
        )
41
      );
42
    }
43
44
45
    /**
46
     * @param string $name
47
     * @return string
48
     */
49
    public function getClassFromName($name) {
50
      $parts = explode(':', $name);
51
      $parts = array_map('ucfirst', $parts);
52
      return $this->namespace . implode('\\', $parts);
53
54
    }
55
56
57
    /**
58
     * @param string $relCommandFile
59
     * @return string
60
     */
61
    public function getClassNameFromFile($relCommandFile) {
62
      $commandName = str_replace('/', ':', $relCommandFile);
63
      $commandName = str_replace('.php', '', $commandName);
64
      $commandClass = $this->namespace . str_replace(':', '\\', $commandName);
65
      return $commandClass;
66
    }
67
68
  }