Inflector   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 2
dl 0
loc 87
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableize() 0 9 2
A classify() 0 9 2
A camelize() 0 9 2
A pluralize() 0 9 2
A singularize() 0 9 2
1
<?php
2
/*
3
 * This file is part of the rafrsr/lib-array2object package.
4
 *
5
 * (c) Rafael SR <https://github.com/rafrsr>
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 Rafrsr\LibArray2Object;
11
12
use Doctrine\Inflector\InflectorFactory;
13
14
/**
15
 * Class Inflector
16
 *
17
 * @package Ynlo\GraphQLBundle\Util
18
 */
19
class Inflector
20
{
21
    /**
22
     * Convert word in to the format for a Doctrine table name. Converts 'ModelName' to 'model_name'
23
     *
24
     * @param string $word Word to tableize
25
     *
26
     * @return string $word  Tableized word
27
     */
28
    public static function tableize($word)
29
    {
30
        // BC with doctrine inflector ^1.0
31
        if (!class_exists('Doctrine\Inflector\InflectorFactory')) {
32
            return \Doctrine\Common\Inflector\Inflector::tableize($word);
33
        }
34
35
        return InflectorFactory::create()->build()->tableize($word);
36
    }
37
38
    /**
39
     * Convert a word in to the format for a Doctrine class name. Converts 'table_name' to 'TableName'
40
     *
41
     * @param string $word Word to classify
42
     *
43
     * @return string $word  Classified word
44
     */
45
    public static function classify($word)
46
    {
47
        // BC with doctrine inflector ^1.0
48
        if (!class_exists('Doctrine\Inflector\InflectorFactory')) {
49
            return \Doctrine\Common\Inflector\Inflector::classify($word);
50
        }
51
52
        return InflectorFactory::create()->build()->classify($word);
53
    }
54
55
    /**
56
     * Camelize a word. This uses the classify() method and turns the first character to lowercase
57
     *
58
     * @param string $word
59
     *
60
     * @return string $word
61
     */
62
    public static function camelize($word)
63
    {
64
        // BC with doctrine inflector ^1.0
65
        if (!class_exists('Doctrine\Inflector\InflectorFactory')) {
66
            return \Doctrine\Common\Inflector\Inflector::camelize($word);
67
        }
68
69
        return InflectorFactory::create()->build()->camelize($word);
70
    }
71
72
    /**
73
     * Return $word in plural form.
74
     *
75
     * @param string $word Word in singular
76
     *
77
     * @return string Word in plural
78
     */
79
    public static function pluralize($word)
80
    {
81
        // BC with doctrine inflector ^1.0
82
        if (!class_exists('Doctrine\Inflector\InflectorFactory')) {
83
            return \Doctrine\Common\Inflector\Inflector::pluralize($word);
84
        }
85
86
        return InflectorFactory::create()->build()->pluralize($word);
87
    }
88
89
    /**
90
     * Return $word in singular form.
91
     *
92
     * @param string $word Word in plural
93
     *
94
     * @return string Word in singular
95
     */
96
    public static function singularize($word)
97
    {
98
        // BC with doctrine inflector ^1.0
99
        if (!class_exists('Doctrine\Inflector\InflectorFactory')) {
100
            return \Doctrine\Common\Inflector\Inflector::singularize($word);
101
        }
102
103
        return InflectorFactory::create()->build()->singularize($word);
104
    }
105
}