Psr4ResourceInflector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 60
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A baseNamespace() 0 6 1
A version() 0 6 1
A inflect() 0 6 1
1
<?php
2
3
namespace Cerbero\FluentApi\Inflectors;
4
5
/**
6
 * Resource inflector using the PSR-4 standard.
7
 *
8
 * @author    Andrea Marco Sartori
9
 */
10
class Psr4ResourceInflector implements ResourceInflectorInterface
11
{
12
    /**
13
     * The base namespace.
14
     *
15
     * @author  Andrea Marco Sartori
16
     * @var     string
17
     */
18
    protected $namespace;
19
20
    /**
21
     * The version number.
22
     *
23
     * @author  Andrea Marco Sartori
24
     * @var     string
25
     */
26
    protected $version;
27
28
    /**
29
     * Set the base namespace.
30
     *
31
     * @author    Andrea Marco Sartori
32
     * @param    string    $namespace
33
     * @return    $this
34
     */
35
    public function baseNamespace($namespace)
36
    {
37
        $this->namespace = $namespace;
38
39
        return $this;
40
    }
41
42
    /**
43
     * Set the version number.
44
     *
45
     * @author    Andrea Marco Sartori
46
     * @param    string    $version
47
     * @return    $this
48
     */
49
    public function version($version)
50
    {
51
        $this->version = ucfirst($version);
52
53
        return $this;
54
    }
55
56
    /**
57
     * Inflect the given name returning the full resource name.
58
     *
59
     * @author    Andrea Marco Sartori
60
     * @param    string    $name
61
     * @return    string
62
     */
63
    public function inflect($name)
64
    {
65
        $segments = [$this->namespace, $this->version, ucfirst($name)];
66
67
        return $this->namespace = implode('\\', array_filter($segments));
68
    }
69
}
70