Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DatabaseCommand
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 setDatabase
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getDatabase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php declare(strict_types=1);
2/*
3 * This file is part of Aplus Framework Dev Commands 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 */
10namespace Framework\CLI\Commands;
11
12use Framework\CLI\Command;
13use Framework\Database\Database;
14use Framework\MVC\App;
15
16/**
17 * Class DatabaseCommand.
18 *
19 * @package dev-commands
20 */
21abstract class DatabaseCommand extends Command
22{
23    protected Database $database;
24    protected string $databaseInstance = 'default';
25    protected array $options = [
26        '--instance' => 'Database instance name.',
27    ];
28
29    public function setDatabase() : static
30    {
31        // @phpstan-ignore-next-line
32        $this->databaseInstance = $this->getConsole()->getOption('instance') ?? 'default';
33        $this->database = App::database($this->databaseInstance); // @phpstan-ignore-line
34        return $this;
35    }
36
37    public function getDatabase() : Database
38    {
39        return $this->database;
40    }
41}