1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Shapin\Datagen\Bridge\Symfony\Bundle\Command; |
6
|
|
|
|
7
|
|
|
use Shapin\Datagen\DBAL\Loader; |
8
|
|
|
use Doctrine\DBAL\Connection; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
14
|
|
|
|
15
|
|
|
class DBALLoadCommand extends Command |
16
|
|
|
{ |
17
|
|
|
private $connection; |
18
|
|
|
private $loader; |
19
|
|
|
|
20
|
1 |
|
public function __construct(Connection $connection, Loader $loader) |
21
|
|
|
{ |
22
|
1 |
|
$this->connection = $connection; |
23
|
1 |
|
$this->loader = $loader; |
24
|
|
|
|
25
|
1 |
|
parent::__construct(); |
26
|
1 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
1 |
|
protected function configure() |
32
|
|
|
{ |
33
|
|
|
$this |
34
|
1 |
|
->setName('shapin:datagen:dbal:load') |
35
|
1 |
|
->setDescription('Load the DBAL schema.') |
36
|
1 |
|
->addOption('groups', 'g', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Which groups should be loaded? (default: all)') |
37
|
|
|
; |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
44
|
|
|
{ |
45
|
1 |
|
$io = new SymfonyStyle($input, $output); |
46
|
1 |
|
$io->title('Create database schema with DBAL.'); |
47
|
|
|
|
48
|
1 |
|
$groups = $input->getOption('groups', []); |
|
|
|
|
49
|
|
|
|
50
|
1 |
|
$statements = $this->loader->getSchema($groups)->toSql($this->connection->getDatabasePlatform()); |
51
|
1 |
|
foreach ($statements as $statement) { |
52
|
|
|
$this->connection->query($statement); |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
$io->success('Schema created successfully.'); |
56
|
|
|
|
57
|
1 |
|
foreach ($this->loader->getFixtures($groups) as $fixture) { |
58
|
|
|
$this->connection->insert($fixture[0], $fixture[1], $fixture[2]); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
$io->success('Fixtures created successfully.'); |
62
|
1 |
|
} |
63
|
|
|
} |
64
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.