Lines
100.00%
20 / 20
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| __toString | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| getAliasIdentifier | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [BO\Zmsbackend\Query\Builder\Dialect\Quote] quoteStructureParts | 100.00% | 16 / 16 | 100.00% | 1 / 1 | 10 | ||
| 5 | class Alias implements \BO\Zmsbackend\Query\Builder\ExpressionInterface | |
| 6 | { | |
| 7 | use \BO\Zmsbackend\Query\Builder\Dialect\Quote; | |
| 8 | ||
| 9 | protected $name; | |
| 10 | protected $alias; | |
| 11 | ||
| 12 | public function __construct($name, $alias) | |
| 13 | { | |
| 14 | $this->name = $this->quoteStructureParts($name, '`'); | |
| 15 | $this->alias = $this->quoteStructureParts($alias, '`'); | |
| 16 | } | |
| 17 | ||
| 18 | public function __toString() | |
| 19 | { | |
| 20 | return $this->name . ' AS ' . $this->alias; | |
| 21 | } | |
| 22 | ||
| 23 | /** @psalm-api */ | |
| 24 | public function getAliasIdentifier() | |
| 25 | { | |
| 26 | return $this->alias; | |
| 27 | } | |
| 28 | } |
From BO\Zmsbackend\Query\Builder\Dialect\Quote
| 18 | trait Quote | |
| 19 | { | |
| 20 | /** | |
| 21 | * Takes a period-separated string and puts the appropriate quote | |
| 22 | * marks around it, guarding against double quoting. | |
| 23 | * | |
| 24 | * @param string|ExpressionInterface $string | |
| 25 | * @param string $quoteMark Mark to use for start and end of quotes | |
| 26 | * @param array $unquotable Any strings that mustn't be quoted (ie *) | |
| 27 | * @return string | |
| 28 | */ | |
| 29 | protected function quoteStructureParts($string, $quoteMark, array $unquotable = []) | |
| 30 | { | |
| 31 | if ($string instanceof ExpressionInterface) { | |
| 32 | return $string; | |
| 33 | } | |
| 34 | ||
| 35 | if ($string === null || strlen($string = trim($string)) === 0) { | |
| 36 | return $string; | |
| 37 | } | |
| 38 | ||
| 39 | $parts = explode('.', $string); | |
| 40 | $rebuild = []; | |
| 41 | foreach ($parts as $p) { | |
| 42 | $p = trim($p); | |
| 43 | if (!in_array($p, $unquotable) && $p != '') { | |
| 44 | // quote at the front | |
| 45 | if (strpos($p, $quoteMark) !== 0) { | |
| 46 | $p = $quoteMark . $p; | |
| 47 | } | |
| 48 | // quote at the back: | |
| 49 | if (strrpos($p, $quoteMark) != (strlen($p) - 1)) { | |
| 50 | $p .= $quoteMark; | |
| 51 | } | |
| 52 | } | |
| 53 | ||
| 54 | if (trim($p) != '') { | |
| 55 | $rebuild[] = $p; | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | return implode('.', $rebuild); | |
| 60 | } | |
| 61 | } |