Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
},
"require": {
"php": " >=8.3",
"doctrine/dbal": "^2.13",
"symfony/config": "^6.4",
"symfony/console": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/yaml": "^6.4"
"doctrine/dbal": "^3.7.0",
"symfony/config": "^7.2",
"symfony/console": "^7.2",
"symfony/dependency-injection": "^7.2",
"symfony/http-kernel": "^7.2",
"symfony/yaml": "^7.2"
},
"require-dev": {
"ibexa/code-style": "~2.0.0",
Expand Down
126 changes: 0 additions & 126 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,131 +1,5 @@
parameters:
ignoreErrors:
-
message: '#^Method Ibexa\\DoctrineSchema\\Builder\\SchemaBuilder\:\:__construct\(\) has parameter \$defaultTableOptions with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Builder/SchemaBuilder.php

-
message: '#^Property Ibexa\\DoctrineSchema\\Builder\\SchemaBuilder\:\:\$defaultTableOptions type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Builder/SchemaBuilder.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Database\\DbPlatform\\PostgreSqlDbPlatform\:\:getDropTableSQL\(\) should return string but returns string\|null\.$#'
identifier: return.type
count: 1
path: src/lib/Database/DbPlatform/PostgreSqlDbPlatform.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Database\\DbPlatformFactory\:\:__construct\(\) has parameter \$dbPlatforms with no value type specified in iterable type iterable\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Database/DbPlatformFactory.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Database\\DbPlatformFactory\:\:createDatabasePlatformFromDriverName\(\) should return Doctrine\\DBAL\\Platforms\\AbstractPlatform\|null but returns Ibexa\\DoctrineSchema\\Database\\DbPlatform\\DbPlatformInterface\|null\.$#'
identifier: return.type
count: 1
path: src/lib/Database/DbPlatformFactory.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:export\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:exportColumns\(\) has parameter \$tableMetadata with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:exportColumns\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:exportForeignKeys\(\) has parameter \$tableMetadata with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:exportForeignKeys\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:exportIndices\(\) has parameter \$tableMetadata with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:exportIndices\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:filterOutIndexDefaultOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Exporter\\Table\\SchemaTableExporter\:\:filterOutIndexDefaultOptions\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Exporter/Table/SchemaTableExporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Importer\\SchemaImporter\:\:addSchemaTableColumns\(\) has parameter \$columnList with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Importer/SchemaImporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Importer\\SchemaImporter\:\:ensureNoExtraKeys\(\) has parameter \$allowedKeys with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Importer/SchemaImporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Importer\\SchemaImporter\:\:ensureNoExtraKeys\(\) has parameter \$tableConfiguration with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Importer/SchemaImporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Importer\\SchemaImporter\:\:importFromArray\(\) has parameter \$schemaDefinition with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Importer/SchemaImporter.php

-
message: '#^Method Ibexa\\DoctrineSchema\\Importer\\SchemaImporter\:\:importSchemaTable\(\) has parameter \$tableConfiguration with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/Importer/SchemaImporter.php

-
message: '#^PHPDoc tag @param has invalid value \(\\Doctrine\\DBAL\\Schema\\Schema target schema\)\: Unexpected token "target", expected variable at offset 124 on line 4$#'
identifier: phpDoc.parseError
count: 1
path: src/lib/Importer/SchemaImporter.php

-
message: '#^Parameter \#1 \$columnNames of method Doctrine\\DBAL\\Schema\\Table\:\:setPrimaryKey\(\) expects array\<string\>, list\<int\|string\> given\.$#'
identifier: argument.type
count: 1
path: src/lib/Importer/SchemaImporter.php

-
message: '#^Method Ibexa\\Tests\\DoctrineSchema\\Exporter\\SchemaExporterTest\:\:providerForTestExport\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down
7 changes: 7 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Ibexa\Contracts\Rector\Sets\IbexaSetList;
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Symfony\Set\SymfonySetList;

return RectorConfig::configure()
Expand All @@ -22,4 +23,10 @@
SymfonySetList::SYMFONY_62,
SymfonySetList::SYMFONY_63,
SymfonySetList::SYMFONY_64,
SymfonySetList::SYMFONY_70,
SymfonySetList::SYMFONY_71,
SymfonySetList::SYMFONY_72,
DoctrineSetList::DOCTRINE_COMMON_20,
DoctrineSetList::DOCTRINE_DBAL_211,
DoctrineSetList::DOCTRINE_DBAL_30,
]);
51 changes: 23 additions & 28 deletions src/bundle/Command/DumpSqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Ibexa\DoctrineSchema\Builder\SchemaBuilder;
use InvalidArgumentException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -37,12 +35,11 @@ final class DumpSqlCommand extends Command
/**
* @phpstan-var array<non-empty-string, class-string<\Doctrine\DBAL\Platforms\AbstractPlatform>>
*/
private const PLATFORM_MAP = [
private const array PLATFORM_MAP = [
'mysql8' => MySQL80Platform::class,
'mysql57' => MySQL57Platform::class,
'mysql' => MySqlPlatform::class,
'mariadb' => MariaDb1027Platform::class,
'postgres' => PostgreSQL100Platform::class,
'mysql' => MySQLPlatform::class,
'mariadb' => MariaDBPlatform::class,
'postgres' => PostgreSQLPlatform::class,
];

public function __construct(Connection $db, SchemaBuilder $schemaBuilder)
Expand Down Expand Up @@ -78,6 +75,11 @@ protected function configure(): void
);
}

/**
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\DBAL\Schema\SchemaException
* @throws \Ibexa\Contracts\DoctrineSchema\Exception\InvalidConfigurationException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$file = $input->getArgument('file');
Expand All @@ -90,14 +92,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$platform = $this->getPlatformForInput($input);

if ($input->getOption('compare')) {
$schemaManager = $this->getSchemaManager();
$fromSchema = $this->introspectSchema($schemaManager);
$schemaManager = $this->db->createSchemaManager();
$fromSchema = $schemaManager->introspectSchema();

$comparator = new Comparator();
$diff = $comparator->compare($fromSchema, $toSchema);
$sqls = $diff->toSql($platform);
$diff = $comparator->compareSchemas($fromSchema, $toSchema);
$sqlStatements = $platform->getAlterSchemaSQL($diff);
} else {
$sqls = $toSchema->toSql($platform);
$sqlStatements = $toSchema->toSql($platform);
}

$io = new SymfonyStyle($input, $output);
Expand All @@ -111,23 +113,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
]
);

foreach ($sqls as $sql) {
foreach ($sqlStatements as $sql) {
$io->writeln($sql . ';');
}

return self::SUCCESS;
}

private function getSchemaManager(): AbstractSchemaManager
{
return $this->db->getSchemaManager();
}

private function introspectSchema(AbstractSchemaManager $schemaManager): Schema
{
return $schemaManager->createSchema();
}

/**
* @throws \Doctrine\DBAL\Exception
*/
private function getPlatformForInput(InputInterface $input): AbstractPlatform
{
$forcePlatform = $input->getOption('force-platform');
Expand All @@ -137,7 +132,7 @@ private function getPlatformForInput(InputInterface $input): AbstractPlatform
}

if (!isset(self::PLATFORM_MAP[$forcePlatform])) {
throw new \InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Invalid --force-platform option. Received "%s", expected one of: "%s"',
$forcePlatform,
implode('","', array_keys(self::PLATFORM_MAP)),
Expand Down
3 changes: 0 additions & 3 deletions src/bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(DoctrineSchemaExtension::EXTENSION_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/DependencyInjection/DoctrineSchemaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class DoctrineSchemaExtension extends Extension
{
public const EXTENSION_NAME = 'ibexa_doctrine_schema';
public const string EXTENSION_NAME = 'ibexa_doctrine_schema';

/**
* Override default extension alias name to include Ibexa vendor in name.
Expand Down
3 changes: 0 additions & 3 deletions src/bundle/DoctrineSchemaBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

class DoctrineSchemaBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function getContainerExtension(): ExtensionInterface
{
return new DoctrineSchemaExtension();
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/SchemaBuilderEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

class SchemaBuilderEvents
{
public const BUILD_SCHEMA = 'ibexa.schema.build_schema';
public const string BUILD_SCHEMA = 'ibexa.schema.build_schema';
}
4 changes: 2 additions & 2 deletions src/contracts/SchemaImporterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface SchemaImporterInterface
* @return \Doctrine\DBAL\Schema\Schema imported schema
*
* @throws \Ibexa\Contracts\DoctrineSchema\Exception\InvalidConfigurationException
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
*/
public function importFromFile(string $schemaFilePath, ?Schema $targetSchema = null): Schema;

Expand All @@ -37,7 +37,7 @@ public function importFromFile(string $schemaFilePath, ?Schema $targetSchema = n
* @return \Doctrine\DBAL\Schema\Schema imported schema
*
* @throws \Ibexa\Contracts\DoctrineSchema\Exception\InvalidConfigurationException
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
*/
public function importFromSource(string $schemaDefinition, ?Schema $targetSchema = null): Schema;
}
11 changes: 11 additions & 0 deletions src/lib/Builder/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ class SchemaBuilder implements APISchemaBuilder

private ?Schema $schema = null;

/** @var mixed[] */
private array $defaultTableOptions;

/**
* @param mixed[] $defaultTableOptions
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
SchemaImporterInterface $schemaImporter,
Expand All @@ -43,6 +47,9 @@ public function __construct(
$this->defaultTableOptions = $defaultTableOptions;
}

/**
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function buildSchema(): Schema
{
$config = new SchemaConfig();
Expand All @@ -57,6 +64,10 @@ public function buildSchema(): Schema
return $this->schema;
}

/**
* @throws \Ibexa\Contracts\DoctrineSchema\Exception\InvalidConfigurationException
* @throws \Doctrine\DBAL\Exception
*/
public function importSchemaFromFile(string $schemaFilePath): Schema
{
return $this->schemaImporter->importFromFile($schemaFilePath, $this->schema);
Expand Down
11 changes: 10 additions & 1 deletion src/lib/Database/DbPlatform/DbPlatformInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
namespace Ibexa\DoctrineSchema\Database\DbPlatform;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;

/**
* @internal
*/
interface DbPlatformInterface
{
/**
* Get name of the driver associated with Database Platform implementation.
* Get the name of the driver associated with Database Platform implementation.
*
* Every Database Platform implementation should extend Doctrine AbstractPlatform
* (or its implementation).
Expand All @@ -26,4 +30,9 @@ public function getDriverName(): string;
* Add event subscribers predefined and required by an implementation.
*/
public function addEventSubscribers(EventManager $eventManager): void;

/**
* Add platform-based configuration to DBAL.
*/
public function configure(Configuration $dbalConfiguration): void;
}
Loading
Loading