Test Setup Failed
Push — develop ( 17b215...d74e9d )
by Freddie
13:13
created

InflectorTrait::getPascalCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Generator\Domain\Traits;
11
12
use Jawira\CaseConverter\Convert;
13
use Symfony\Component\Inflector\Inflector;
14
15
trait InflectorTrait
16
{
17
    protected function getPascalCase(string $string): string
18
    {
19
        return (new Convert($string))->toPascal();
20
    }
21
22
    protected function getCamelCase(string $string): string
23
    {
24
        return (new Convert($string))->toCamel();
25
    }
26
27
    protected function getSnakeCase(string $string): string
28
    {
29
        return (new Convert($string))->toSnake();
30
    }
31
32
    protected function getDashCase(string $string): string
33
    {
34
        return (new Convert($string))->toKebab();
35
    }
36
37
    protected function getSingularize(string $string): string
38
    {
39
        $singularize = Inflector::singularize($string);
40
41
        return \is_array($singularize)
42
            ? $singularize[0]
43
            : $singularize;
44
    }
45
46
    protected function getPluralize(string $string): string
47
    {
48
        $pluralize = Inflector::pluralize($this->getSingularize($string));
49
50
        return \is_array($pluralize)
51
            ? $pluralize[0]
52
            : $pluralize;
53
    }
54
}
55