Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AbstractFormatter | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
9 | |
100.00% |
1 / 1 |
| unquoteId | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
9 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Db\Sql\Schema\Formatter; |
| 16 | |
| 17 | /** |
| 18 | * Schema formatter abstract class |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Db |
| 22 | * @author Nick Sagona, III <nick@popphp.org> |
| 23 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 7.0.0 |
| 26 | */ |
| 27 | abstract class AbstractFormatter |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Un-quote identifier |
| 32 | * |
| 33 | * @param string $identifier |
| 34 | * @return string |
| 35 | */ |
| 36 | public static function unquoteId(string $identifier): string |
| 37 | { |
| 38 | if (str_contains($identifier, '.')) { |
| 39 | $identifierAry = explode('.', $identifier); |
| 40 | foreach ($identifierAry as $key => $val) { |
| 41 | $first = substr($val, 0, 1); |
| 42 | if (($first == '`') || ($first == '"') || ($first == '[')) { |
| 43 | $val = substr($val, 1); |
| 44 | $val = substr($val, 0, -1); |
| 45 | } |
| 46 | $identifierAry[$key] = $val; |
| 47 | } |
| 48 | $identifier = implode('.', $identifierAry); |
| 49 | } else { |
| 50 | $first = substr($identifier, 0, 1); |
| 51 | |
| 52 | if (($first == '`') || ($first == '"') || ($first == '[')) { |
| 53 | $identifier = substr($identifier, 1); |
| 54 | $identifier = substr($identifier, 0, -1); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return $identifier; |
| 59 | } |
| 60 | |
| 61 | } |