Issues (1426)

app/src/Command/SqlShell.php (17 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace Db3v4l\Command;
4
5
use Db3v4l\API\Interfaces\SqlExecutor\Forked\ShellExecutor;
6
use Db3v4l\Core\SqlExecutor\Forked\NativeClient;
7
use Db3v4l\Service\DatabaseConfigurationManager;
8
use Db3v4l\Service\SqlExecutorFactory;
9
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
class SqlShell extends BaseCommand
0 ignored issues
show
Missing doc comment for class SqlShell
Loading history...
14
{
15
    protected static $defaultName = 'db3v4l:sql:shell';
16
17
    /** @var DatabaseConfigurationManager $dbConfigurationManager */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
18
    protected $dbConfigurationManager;
19
    /** @var SqlExecutorFactory $executorFactory */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
20
    protected $executorFactory;
21
22
    public function __construct(
0 ignored issues
show
Missing doc comment for function __construct()
Loading history...
23
        DatabaseConfigurationManager $dbConfigurationManager,
24
        SqlExecutorFactory $executorFactory)
0 ignored issues
show
The closing parenthesis of a multi-line function declaration must be on a new line
Loading history...
25
    {
0 ignored issues
show
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
26
        $this->dbConfigurationManager = $dbConfigurationManager;
27
        $this->executorFactory = $executorFactory;
28
29
        parent::__construct();
30
    }
31
32
    protected function configure()
0 ignored issues
show
Missing doc comment for function configure()
Loading history...
33
    {
34
        $this
35
            ->setDescription('Connects to one of the configured database instances, using the appropriate native sql client')
36
            ->addOption('instance', 'i', InputOption::VALUE_REQUIRED, 'The instance to connect to', null)
37
            ->addOption('database', 'd', InputOption::VALUE_REQUIRED, 'The name of an existing database to use')
0 ignored issues
show
Space after closing parenthesis of function call prohibited
Loading history...
38
        ;
39
    }
40
41
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Missing doc comment for function execute()
Loading history...
42
    {
43
        $instanceName = $input->getOption('instance');
44
        $dbName = $input->getOption('database');
45
46
        if ($instanceName == null) {
47
            throw new \Exception("Please provide an instance name");
48
        }
49
50
        $dbConnectionSpec = $this->dbConfigurationManager->getInstanceConfiguration($instanceName);
51
        if ($dbName != '') {
52
            $dbConnectionSpec['dbname'] = $dbName;
53
        }
54
        $executor = $this->executorFactory->createForkedExecutor($instanceName, $dbConnectionSpec, NativeClient::EXECUTION_STRATEGY, false);
55
56
        if (! $executor instanceof ShellExecutor) {
57
            throw new \Exception("Can not start an interactive shell for databases of type '{$dbConnectionSpec['vendor']}'");
58
        }
59
60
        $process = $executor->getExecuteShellProcess();
61
62
        $process->setTty(true);
63
        $process->run();
64
65
        return $process->getExitCode();
66
    }
67
}
68