| Total Complexity | 7 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class Column implements IColumn |
||
| 11 | { |
||
| 12 | protected IQueryPart|string $expr; |
||
| 13 | |||
| 14 | protected ?string $alias = null; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Expr constructor. |
||
| 18 | * |
||
| 19 | * @param IQueryPart|string $expr column name or expression to be used |
||
| 20 | * @param string|null $alias |
||
| 21 | */ |
||
| 22 | 47 | public function __construct(IQueryPart|string $expr, ?string $alias = null) |
|
| 23 | { |
||
| 24 | 47 | $this->expr = $expr; |
|
| 25 | 47 | $this->alias = $alias; |
|
| 26 | 47 | } |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | 37 | public function __toString(): string |
|
| 32 | { |
||
| 33 | 37 | $expr = is_string($this->expr) ? $this->expr : (string)$this->expr; |
|
| 34 | |||
| 35 | 37 | if ($this->expr instanceof Select) { |
|
| 36 | 4 | $expr = '(' . str_replace(PHP_EOL, ' ', $expr) . ')'; |
|
| 37 | } |
||
| 38 | |||
| 39 | 37 | if ($this->alias === null) { |
|
| 40 | 32 | return $expr; |
|
| 41 | } |
||
| 42 | |||
| 43 | 10 | return sprintf('%s AS %s', $expr, $this->alias); |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return array |
||
| 48 | */ |
||
| 49 | 8 | public function getParams(): array |
|
| 56 | } |
||
| 57 | } |
||
| 58 |