Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Table
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 parse
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Db\Sql\Parser;
15
16/**
17 * Table parser class
18 *
19 * @category   Pop
20 * @package    Pop\Db
21 * @author     Nick Sagona, III <dev@nolainteractive.com>
22 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    6.5.0
25 */
26class Table
27{
28
29    /**
30     * Method to convert a camelCase string to an under_score string for database table naming conventions
31     *
32     * @param  string $tableClass
33     * @return string
34     */
35    public static function parse(string $tableClass): string
36    {
37        $chars   = str_split($tableClass);
38        $dbTable = null;
39
40        foreach ($chars as $i => $char) {
41            if ($i == 0) {
42                $dbTable .= strtolower($char);
43            } else {
44                $dbTable .= (ctype_upper($char)) ? ('_' . strtolower($char)) : $char;
45            }
46        }
47
48        return $dbTable;
49    }
50
51}