summaryrefslogtreecommitdiffstats
path: root/lib/private/DB/MigrationService.php
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-12-01 13:28:11 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-09-05 09:20:26 +0200
commite966cfbc4b168a536d93d1c7efb82ed442343aef (patch)
tree864a640d0f50647563108aa74847c1f7b1b5e385 /lib/private/DB/MigrationService.php
parente54724728159e96e7f2c24d77a5a22d081f80aac (diff)
downloadnextcloud-server-e966cfbc4b168a536d93d1c7efb82ed442343aef.tar.gz
nextcloud-server-e966cfbc4b168a536d93d1c7efb82ed442343aef.zip
Cleanup plsam issues in DB/ContactsManager and Console
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/private/DB/MigrationService.php')
-rw-r--r--lib/private/DB/MigrationService.php58
1 files changed, 20 insertions, 38 deletions
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 71d7b51d149..29df1c1f78d 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -58,7 +58,7 @@ class MigrationService {
/**
* @throws \Exception
*/
- public function __construct($appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null) {
+ public function __construct(string $appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null) {
$this->appName = $appName;
$this->connection = $connection;
if ($output === null) {
@@ -100,18 +100,15 @@ class MigrationService {
/**
* Returns the name of the app for which this migration is executed
- *
- * @return string
*/
- public function getApp() {
+ public function getApp(): string {
return $this->appName;
}
/**
- * @return bool
* @codeCoverageIgnore - this will implicitly tested on installation
*/
- private function createMigrationTable() {
+ private function createMigrationTable(): bool {
if ($this->migrationTableCreated) {
return false;
}
@@ -188,7 +185,7 @@ class MigrationService {
->where($qb->expr()->eq('app', $qb->createNamedParameter($this->getApp())))
->orderBy('version');
- $result = $qb->execute();
+ $result = $qb->executeQuery();
$rows = $result->fetchAll(\PDO::FETCH_COLUMN);
$result->closeCursor();
@@ -197,15 +194,17 @@ class MigrationService {
/**
* Returns all versions which are available in the migration folder
- *
- * @return array
+ * @return list<string>
*/
- public function getAvailableVersions() {
+ public function getAvailableVersions(): array {
$this->ensureMigrationsAreLoaded();
return array_map('strval', array_keys($this->migrations));
}
- protected function findMigrations() {
+ /**
+ * @return array<string, string>
+ */
+ protected function findMigrations(): array {
$directory = realpath($this->migrationsPath);
if ($directory === false || !file_exists($directory) || !is_dir($directory)) {
return [];
@@ -322,10 +321,9 @@ class MigrationService {
/**
* Return the explicit version for the aliases; current, next, prev, latest
*
- * @param string $alias
* @return mixed|null|string
*/
- public function getMigration($alias) {
+ public function getMigration(string $alias) {
switch ($alias) {
case 'current':
return $this->getCurrentVersion();
@@ -342,29 +340,22 @@ class MigrationService {
return '0';
}
- /**
- * @param string $version
- * @param int $delta
- * @return null|string
- */
- private function getRelativeVersion($version, $delta) {
+ private function getRelativeVersion(string $version, int $delta): ?string {
$this->ensureMigrationsAreLoaded();
$versions = $this->getAvailableVersions();
- array_unshift($versions, 0);
+ array_unshift($versions, '0');
+ /** @var int $offset */
$offset = array_search($version, $versions, true);
if ($offset === false || !isset($versions[$offset + $delta])) {
// Unknown version or delta out of bounds.
return null;
}
- return (string) $versions[$offset + $delta];
+ return (string)$versions[$offset + $delta];
}
- /**
- * @return string
- */
- private function getCurrentVersion() {
+ private function getCurrentVersion(): string {
$m = $this->getMigratedVersions();
if (count($m) === 0) {
return '0';
@@ -374,11 +365,9 @@ class MigrationService {
}
/**
- * @param string $version
- * @return string
* @throws \InvalidArgumentException
*/
- private function getClass($version) {
+ private function getClass(string $version): string {
$this->ensureMigrationsAreLoaded();
if (isset($this->migrations[$version])) {
@@ -390,21 +379,16 @@ class MigrationService {
/**
* Allows to set an IOutput implementation which is used for logging progress and messages
- *
- * @param IOutput $output
*/
- public function setOutput(IOutput $output) {
+ public function setOutput(IOutput $output): void {
$this->output = $output;
}
/**
* Applies all not yet applied versions up to $to
- *
- * @param string $to
- * @param bool $schemaOnly
* @throws \InvalidArgumentException
*/
- public function migrate($to = 'latest', $schemaOnly = false) {
+ public function migrate(string $to = 'latest', bool $schemaOnly = false): void {
if ($schemaOnly) {
$this->migrateSchemaOnly($to);
return;
@@ -425,11 +409,9 @@ class MigrationService {
/**
* Applies all not yet applied versions up to $to
- *
- * @param string $to
* @throws \InvalidArgumentException
*/
- public function migrateSchemaOnly($to = 'latest') {
+ public function migrateSchemaOnly(string $to = 'latest'): void {
// read known migrations
$toBeExecuted = $this->getMigrationsToExecute($to);