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

Inflect::camelize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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