Completed
Pull Request — master (#90)
by Jonathan
02:32
created

Inflect   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 60
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A pluralize() 0 3 1
A tableize() 0 3 1
A camelize() 0 3 1
A singularize() 0 3 1
A ucwords() 0 3 1
A classify() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector;
6
7
use function lcfirst;
8
use function preg_replace;
9
use function str_replace;
10
use function strtolower;
11
use function ucwords;
12
13
class Inflect implements InflectInterface
14
{
15
    /** @var Singularizer */
16
    private $singularizer;
17
18
    /** @var Pluralizer */
19
    private $pluralizer;
20
21 4
    public function __construct(Singularizer $singularizer, Pluralizer $pluralizer)
22
    {
23 4
        $this->singularizer = $singularizer;
24 4
        $this->pluralizer   = $pluralizer;
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 3
    public function tableize(string $word) : string
31
    {
32 3
        return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 11
    public function classify(string $word) : string
39
    {
40 11
        return str_replace([' ', '_', '-'], '', ucwords($word, ' _-'));
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 5
    public function camelize(string $word) : string
47
    {
48 5
        return lcfirst($this->classify($word));
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 2
    public function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string
55
    {
56 2
        return ucwords($string, $delimiters);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 256
    public function pluralize(string $word) : string
63
    {
64 256
        return $this->pluralizer->inflect($word);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 256
    public function singularize(string $word) : string
71
    {
72 256
        return $this->singularizer->inflect($word);
73
    }
74
}
75