Completed
Push — develop ( eeebfd...e7b4cf )
by Andrea Marco
06:26
created

Inflector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 1
cbo 1
dl 0
loc 87
ccs 13
cts 13
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A of() 0 6 1
A getRequest() 0 4 1
A compose() 0 6 1
A getJob() 0 4 1
1
<?php
2
3
namespace Cerbero\Workflow\Inflectors;
4
5
use Cerbero\Workflow\Wrappers\NamespaceDetectorInterface;
6
7
/**
8
 * Word inflector.
9
 *
10
 * @author	Andrea Marco Sartori
11
 */
12
class Inflector implements InflectorInterface
13
{
14
    /**
15
     * @author	Andrea Marco Sartori
16
     *
17
     * @var string $word	Word to inflect.
18
     */
19
    protected $word;
20
21
    /**
22
     * @author	Andrea Marco Sartori
23
     *
24
     * @var string $namespace	The application namespace.
25
     */
26
    protected $namespace;
27
28
    /**
29
     * Set the application namespace.
30
     *
31
     * @author	Andrea Marco Sartori
32
     *
33
     * @param Cerbero\Workflow\Wrappers\NamespaceDetectorInterface $detector Application namespace detector.
34
     *
35
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
36
     */
37 12
    public function __construct(NamespaceDetectorInterface $detector)
38
    {
39 12
        $this->namespace = $detector->detect();
40 12
    }
41
42
    /**
43
     * Set the word to inflect.
44
     *
45
     * @author	Andrea Marco Sartori
46
     *
47
     * @param string $word
48
     *
49
     * @return $this
50
     */
51 9
    public function of($word)
52
    {
53 9
        $this->word = $word;
54
55 9
        return $this;
56
    }
57
58
    /**
59
     * Retrieve the inflected request.
60
     *
61
     * @author	Andrea Marco Sartori
62
     *
63
     * @return string
64
     */
65 3
    public function getRequest()
66
    {
67 3
        return $this->compose('Request', 'Http\Requests');
68
    }
69
70
    /**
71
     * Compose the word to inflect.
72
     *
73
     * @author	Andrea Marco Sartori
74
     *
75
     * @param string $suffix
76
     * @param string $path
77
     *
78
     * @return string
79
     */
80 6
    protected function compose($suffix, $path)
81
    {
82 6
        $name = ucfirst($this->word).$suffix;
83
84 6
        return $this->namespace."\\{$path}\\{$name}";
85
    }
86
87
    /**
88
     * Retrieve the inflected job.
89
     *
90
     * @author	Andrea Marco Sartori
91
     *
92
     * @return string
93
     */
94 3
    public function getJob()
95
    {
96 3
        return $this->compose('Job', 'Jobs');
97
    }
98
}
99