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
Drop
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
8
100.00% covered (success)
100.00%
1 / 1
 ifExists
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 cascade
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
5
 __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 DROP 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 Drop extends AbstractTable
28{
29
30    /**
31     * IF EXISTS flag
32     * @var bool
33     */
34    protected bool $ifExists = false;
35
36    /**
37     * CASCADE flag
38     * @var bool
39     */
40    protected bool $cascade  = false;
41
42    /**
43     * Set the IF EXISTS flag
44     *
45     * @return Drop
46     */
47    public function ifExists(): Drop
48    {
49        $this->ifExists = true;
50        return $this;
51    }
52
53    /**
54     * Set the CASCADE flag
55     *
56     * @return Drop
57     */
58    public function cascade(): Drop
59    {
60        $this->cascade = true;
61        return $this;
62    }
63
64    /**
65     * Render the table schema
66     *
67     * @return string
68     */
69    public function render(): string
70    {
71        return 'DROP TABLE ' . ((($this->ifExists) && ($this->dbType != self::SQLSRV)) ? 'IF EXISTS ' : null)
72            . $this->quoteId($this->table) . ((($this->isPgsql()) && ($this->cascade)) ? ' CASCADE' : null) . ';' . PHP_EOL;
73    }
74
75    /**
76     * Render the table schema to string
77     *
78     * @return string
79     */
80    public function __toString(): string
81    {
82        return $this->render();
83    }
84
85}