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

aplus-framework / database / 24917719441

25 Apr 2026 12:16AM UTC coverage: 99.797% (-0.04%) from 99.837%
24917719441

push

github

natanfelles
Update test with MySQL

2453 of 2458 relevant lines covered (99.8%)

11.05 hits per line

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

92.86
/src/Manipulation/Traits/Explain.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\Manipulation\Traits;
11

12
use Framework\Database\Result\Explain as Result;
13
use InvalidArgumentException;
14

15
/**
16
 * Trait Explain.
17
 *
18
 * @see https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/analyze-and-explain-statements/explain
19
 *
20
 * @package database
21
 *
22
 * @since 4
23
 */
24
trait Explain
25
{
26
    /**
27
     * @see https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/analyze-and-explain-statements/explain#explain-extended
28
     */
29
    public const string EXP_EXTENDED = 'EXTENDED';
30
    /**
31
     * @see https://mariadb.com/docs/server/server-usage/partitioning-tables/partition-pruning-and-selection
32
     */
33
    public const string EXP_PARTITIONS = 'PARTITIONS';
34
    /**
35
     * @see https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/analyze-and-explain-statements/explain-format-json
36
     */
37
    public const string EXP_FORMAT_JSON = 'FORMAT=JSON';
38

39
    /**
40
     * EXPLAIN provides information about statements.
41
     *
42
     * @param string|null $option
43
     *
44
     * @see https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/analyze-and-explain-statements/explain
45
     *
46
     * @return array<int,Result>
47
     */
48
    public function explain(?string $option = null) : array
49
    {
50
        if ($option !== null) {
3✔
51
            $opt = \strtoupper($option);
1✔
52
            if (!\in_array($opt, [
1✔
53
                static::EXP_EXTENDED,
1✔
54
                static::EXP_FORMAT_JSON,
1✔
55
                static::EXP_PARTITIONS,
1✔
56
            ], true)) {
1✔
57
                throw new InvalidArgumentException('Invalid EXPLAIN option: ' . $option);
1✔
58
            }
59
            $option = ' ' . $opt;
×
60
        }
61
        $sql = 'EXPLAIN' . $option . \PHP_EOL . $this->sql();
2✔
62
        $results = [];
2✔
63
        foreach ($this->database->query($sql)->fetchAll() as $row) {
2✔
64
            $results[] = new Result($row); // @phpstan-ignore-line
2✔
65
        }
66
        return $results;
2✔
67
    }
68
}
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