• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aplus-framework / database / 15202200207

21 Apr 2025 08:34PM UTC coverage: 99.02%. Remained the same
15202200207

push

github

natanfelles
Merge branch 'development'

2426 of 2450 relevant lines covered (99.02%)

10.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Definition/DropSchema.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of Aplus Framework Database Library.
4
 *
5
 * (c) Natan Felles <natanfelles@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Framework\Database\Definition;
11

12
use Framework\Database\Statement;
13
use LogicException;
14

15
/**
16
 * Class DropSchema.
17
 *
18
 * @see https://mariadb.com/kb/en/drop-database/
19
 *
20
 * @package database
21
 */
22
class DropSchema extends Statement
23
{
24
    /**
25
     * @return static
26
     */
27
    public function ifExists() : static
28
    {
29
        $this->sql['if_exists'] = true;
3✔
30
        return $this;
3✔
31
    }
32

33
    protected function renderIfExists() : ?string
34
    {
35
        if (!isset($this->sql['if_exists'])) {
6✔
36
            return null;
3✔
37
        }
38
        return ' IF EXISTS';
3✔
39
    }
40

41
    /**
42
     * @param string $schemaName
43
     *
44
     * @return static
45
     */
46
    public function schema(string $schemaName) : static
47
    {
48
        $this->sql['schema'] = $schemaName;
6✔
49
        return $this;
6✔
50
    }
51

52
    protected function renderSchema() : string
53
    {
54
        if (isset($this->sql['schema'])) {
6✔
55
            return ' ' . $this->database->protectIdentifier($this->sql['schema']);
5✔
56
        }
57
        throw new LogicException('SCHEMA name must be set');
1✔
58
    }
59

60
    public function sql() : string
61
    {
62
        $sql = 'DROP SCHEMA' . $this->renderIfExists();
6✔
63
        $sql .= $this->renderSchema() . \PHP_EOL;
6✔
64
        return $sql;
5✔
65
    }
66

67
    /**
68
     * Runs the CREATE SCHEMA statement.
69
     *
70
     * @return int|string The number of affected rows
71
     */
72
    public function run() : int | string
73
    {
74
        return $this->database->exec($this->sql());
3✔
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc