Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Rename
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 to
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(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 */
15namespace Pop\Db\Sql\Schema;
16
17/**
18 * Schema RENAME table 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 */
27class Rename extends AbstractTable
28{
29
30    /**
31     * Rename table name
32     * @var ?string
33     */
34    protected ?string $to = null;
35
36    /**
37     * Set the rename table name
38     *
39     * @param  string $table
40     * @return Rename
41     */
42    public function to(string $table): Rename
43    {
44        $this->to = $table;
45        return $this;
46    }
47
48    /**
49     * Get the rename table name
50     *
51     * @return string
52     */
53    public function getTo(): string
54    {
55        return $this->to;
56    }
57
58    /**
59     * Render the table schema
60     *
61     * @return string
62     */
63    public function render(): string
64    {
65        return ($this->isMysql()) ?
66            'RENAME TABLE ' . $this->quoteId($this->table) . ' TO ' . $this->quoteId($this->to) . ';' . PHP_EOL :
67            'ALTER TABLE ' . $this->quoteId($this->table) . ' RENAME TO ' . $this->quoteId($this->to) . ';' . PHP_EOL;
68    }
69
70    /**
71     * Render the table schema to string
72     *
73     * @return string
74     */
75    public function __toString(): string
76    {
77        return $this->render();
78    }
79
80}