Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Table | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| parse | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Db\Sql\Parser; |
| 15 | |
| 16 | /** |
| 17 | * Table parser class |
| 18 | * |
| 19 | * @category Pop |
| 20 | * @package Pop\Db |
| 21 | * @author Nick Sagona, III <dev@noladev.com> |
| 22 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 23 | * @license https://www.popphp.org/license New BSD License |
| 24 | * @version 6.7.0 |
| 25 | */ |
| 26 | class 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 | } |