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

aplus-framework / database / 14372198759

27 Jan 2025 09:09PM UTC coverage: 99.02%. Remained the same
14372198759

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

0.0
/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/kb/en/explain/
19
 *
20
 * @package database
21
 *
22
 * @since 4
23
 */
24
trait Explain
25
{
26
    /**
27
     * @see https://mariadb.com/kb/en/explain/#explain-extended
28
     */
29
    public const string EXP_EXTENDED = 'EXTENDED';
30
    /**
31
     * https://mariadb.com/kb/en/partition-pruning-and-selection/.
32
     */
33
    public const string EXP_PARTITIONS = 'PARTITIONS';
34
    /**
35
     * @see https://mariadb.com/kb/en/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/kb/en/explain/
45
     *
46
     * @return array<int,Result>
47
     */
48
    public function explain(?string $option = null) : array
49
    {
50
        if ($option !== null) {
×
51
            $opt = \strtoupper($option);
×
52
            if (!\in_array($opt, [
×
53
                static::EXP_EXTENDED,
×
54
                static::EXP_FORMAT_JSON,
×
55
                static::EXP_PARTITIONS,
×
56
            ], true)) {
×
57
                throw new InvalidArgumentException('Invalid EXPLAIN option: ' . $option);
×
58
            }
59
            $option = ' ' . $opt;
×
60
        }
61
        $sql = 'EXPLAIN' . $option . \PHP_EOL . $this->sql();
×
62
        $results = [];
×
63
        foreach ($this->database->query($sql)->fetchAll() as $row) {
×
64
            $results[] = new Result($row); // @phpstan-ignore-line
×
65
        }
66
        return $results;
×
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