Repository: symfony/symfony
File: src/Symfony/Bridge/Doctrine/SchemaListener/AbstractSchemaListener.php (PHP)

Code before:

namespace Symfony\Bridge\Doctrine\SchemaListener;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;

abstract class AbstractSchemaListener
{
    abstract public function postGenerateSchema(GenerateSchemaEventArgs $event): void;

    protected function filterSchemaChanges(Schema $schema, Connection $connection, callable $configurator): void
    {
        $filter = $connection->getConfiguration()->getSchemaAssetsFilter();

        if (null === $filter) {
            $configurator();

            return;
        }

        $getTableNames = static fn (Schema $schema): array => array_map(static fn (Table $table) => $table->getName(), $schema->getTables());
        $previousTableNames = $getTableNames($schema);
        $previousSequenceNames = array_map(static fn (Sequence $sequence) => $sequence->getName(), $schema->getSequences());

        $configurator();

        foreach (array_diff($getTableNames($schema), $previousTableNames) as $addedTable) {
            if (!$filter($addedTable)) {
                $schema->dropTable($addedTable);
            }
        }

        foreach (array_diff(array_map(static fn (Sequence $sequence) => $sequence->getName(), $schema->getSequences()), $previousSequenceNames) as $addedSequence) {
            if (!$filter($addedSequence)) {
                $schema->dropSequence($addedSequence);
            }
        }
    }

    protected function getIsSameDatabaseChecker(Connection $connection): \Closure
    {
        return static function (\Closure $exec) use ($connection): bool {
            $schemaManager = method_exists($connection, 'createSchemaManager') ? $connection->createSchemaManager() : $connection->getSchemaManager();
            $checkTable = 'schema_subscriber_check_'.bin2hex(random_bytes(7));
            $table = new Table($checkTable);
            $table->addColumn('id', Types::INTEGER)

Review comment (suggestion):
we might reuse the closure more by dropping the types, WDYT?
```suggestion
        $getNames = static fn ($array) => array_map(static fn ($object) => $object->getName(), $array);
```

Code after:

namespace Symfony\Bridge\Doctrine\SchemaListener;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;

abstract class AbstractSchemaListener
{
    abstract public function postGenerateSchema(GenerateSchemaEventArgs $event): void;

    protected function filterSchemaChanges(Schema $schema, Connection $connection, callable $configurator): void
    {
        $filter = $connection->getConfiguration()->getSchemaAssetsFilter();

        if (null === $filter) {
            $configurator();

            return;
        }

        $getNames = static fn ($array) => array_map(static fn ($object) => $object->getName(), $array);
        $previousTableNames = $getNames($schema->getTables());
        $previousSequenceNames = $getNames($schema->getSequences());

        $configurator();

        foreach (array_diff($getNames($schema->getTables()), $previousTableNames) as $addedTable) {
            if (!$filter($addedTable)) {
                $schema->dropTable($addedTable);
            }
        }

        foreach (array_diff($getNames($schema->getSequences()), $previousSequenceNames) as $addedSequence) {
            if (!$filter($addedSequence)) {
                $schema->dropSequence($addedSequence);
            }
        }
    }

    protected function getIsSameDatabaseChecker(Connection $connection): \Closure
    {
        return static function (\Closure $exec) use ($connection): bool {
            $schemaManager = method_exists($connection, 'createSchemaManager') ? $connection->createSchemaManager() : $connection->getSchemaManager();
            $checkTable = 'schema_subscriber_check_'.bin2hex(random_bytes(7));
            $table = new Table($checkTable);
            $table->addColumn('id', Types::INTEGER)
                ->setAutoincrement(true)