Issues (1426)

app/src/Command/UserDrop.php (29 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace Db3v4l\Command;
4
5
use Db3v4l\Core\DatabaseSchemaManager;
0 ignored issues
show
The type Db3v4l\Core\DatabaseSchemaManager 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...
6
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...
7
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...
8
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...
9
10
class UserDrop extends DatabaseManagingCommand
0 ignored issues
show
Missing doc comment for class UserDrop
Loading history...
11
{
12
    protected static $defaultName = 'db3v4l:user:drop';
13
14
    protected function configure()
0 ignored issues
show
Missing doc comment for function configure()
Loading history...
15
    {
16
        $this
17
            ->setDescription('Drops a database user in parallel on all configured database instances')
18
            ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'The name of the user to drop')
19
            ->addCommonOptions()
0 ignored issues
show
Space after closing parenthesis of function call prohibited
Loading history...
20
        ;
21
    }
22
23
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
24
     * @param InputInterface $input
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
25
     * @param OutputInterface $output
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
26
     * @return int
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
27
     * @throws \Exception
0 ignored issues
show
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
28
     */
29
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $start = microtime(true);
32
33
        // as per https://www.php.net/manual/en/function.ignore-user-abort.php: for cli scripts, it is probably a good idea
34
        // to use ignore_user_abort
35
        ignore_user_abort(true);
36
37
        $this->setOutput($output);
38
        $this->setVerbosity($output->getVerbosity());
39
40
        $instanceList = $this->parseCommonOptions($input);
41
42
        $userName = $input->getOption('user');
43
44
        if ($userName == null) {
45
            throw new \Exception("Please provide a username");
46
        }
47
48
        if ($this->outputFormat === 'text') {
49
            $this->writeln('<info>Dropping users...</info>');
50
        }
51
52
        $userToDropSpecs = [];
53
        foreach($instanceList as $instanceName => $instanceSpecs) {
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
54
            $userToDropSpecs[$instanceName] = [
55
                'user' => $userName
56
            ];
57
        }
58
        $results = $this->dropUsers($instanceList, $userToDropSpecs);
59
60
        // BC with versions < 0.8
61
        $results['data'] = null;
62
63
        $time = microtime(true) - $start;
64
65
        $this->writeResults($results, $time);
66
67
        return (int)$results['failed'];
68
    }
69
70
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
71
     * @param $instanceList
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
72
     * @param $userToDropSpecs
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
73
     * @param bool $ifExists
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
74
     * @return array
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
75
     * @throws \Exception
0 ignored issues
show
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
76
     */
77
    protected function dropUsers($instanceList, $userToDropSpecs, $ifExists = false)
78
    {
79
        return $this->executeSqlAction(
80
            $instanceList,
81
            'Dropping of user',
82
            function ($schemaManager, $instanceName) use ($userToDropSpecs, $ifExists) {
83
                $dbConnectionSpec = $userToDropSpecs[$instanceName];
84
                /** @var DatabaseSchemaManager $schemaManager */
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...
85
                return $schemaManager->getDropUserSqlAction(
86
                    $dbConnectionSpec['user'],
87
                    $ifExists
88
                );
89
            }
90
        );
91
    }
92
}
93