HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/payments-gateway/vendor/doctrine/migrations/src/Rollup.php
<?php

declare(strict_types=1);

namespace Doctrine\Migrations;

use Doctrine\Migrations\Exception\RollupFailed;
use Doctrine\Migrations\Metadata\Storage\MetadataStorage;
use Doctrine\Migrations\Version\ExecutionResult;
use Doctrine\Migrations\Version\Version;

use function count;

/**
 * The Rollup class is responsible for deleting all previously executed migrations from the versions table
 * and marking the freshly dumped schema migration (that was created with SchemaDumper) as migrated.
 *
 * @internal
 */
class Rollup
{
    public function __construct(
        private readonly MetadataStorage $metadataStorage,
        private readonly MigrationsRepository $migrationRepository,
    ) {
    }

    /** @throws RollupFailed */
    public function rollup(): Version
    {
        $versions = $this->migrationRepository->getMigrations();

        if (count($versions) === 0) {
            throw RollupFailed::noMigrationsFound();
        }

        if (count($versions) > 1) {
            throw RollupFailed::tooManyMigrations();
        }

        $this->metadataStorage->reset();

        $result = new ExecutionResult($versions->getItems()[0]->getVersion());
        $this->metadataStorage->complete($result);

        return $result->getVersion();
    }
}