StandardNameResolver::getNameFromClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 2
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
  }