From 81cddb2bc6ec04e11a671b6a3cfd849e026b2646 Mon Sep 17 00:00:00 2001
From: Marc Alexander <admin@m-a-styles.de>
Date: Mon, 17 Jan 2022 17:09:38 +0100
Subject: [PATCH] [ticket/16741] Clean up functions, add missing docblocks and
 return type hints

PHPBB3-16741
---
 phpBB/phpbb/db/doctrine/comparator.php        |  2 +-
 .../phpbb/db/doctrine/postgresql_platform.php | 40 +++++++++++--------
 phpBB/phpbb/db/doctrine/table_helper.php      |  3 ++
 phpBB/phpbb/db/tools/doctrine.php             |  4 +-
 4 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/phpBB/phpbb/db/doctrine/comparator.php b/phpBB/phpbb/db/doctrine/comparator.php
index 4a3d3c14f6..854db1cd30 100644
--- a/phpBB/phpbb/db/doctrine/comparator.php
+++ b/phpBB/phpbb/db/doctrine/comparator.php
@@ -26,7 +26,7 @@ class comparator extends \Doctrine\DBAL\Schema\Comparator
 
 		if ($diff === false)
 		{
-			return $diff;
+			return false;
 		}
 
 		if (!is_array($diff->changedColumns))
diff --git a/phpBB/phpbb/db/doctrine/postgresql_platform.php b/phpBB/phpbb/db/doctrine/postgresql_platform.php
index d92800b4bd..1e81e59b19 100644
--- a/phpBB/phpbb/db/doctrine/postgresql_platform.php
+++ b/phpBB/phpbb/db/doctrine/postgresql_platform.php
@@ -36,7 +36,7 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritdoc}
 	 */
-	public function getIdentitySequenceName($tableName, $columnName)
+	public function getIdentitySequenceName($tableName, $columnName): string
 	{
 		return $tableName . '_seq';
 	}
@@ -44,7 +44,7 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritDoc}
 	 */
-	public function getIntegerTypeDeclarationSQL(array $column)
+	public function getIntegerTypeDeclarationSQL(array $column): string
 	{
 		return 'INT';
 	}
@@ -52,7 +52,7 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritDoc}
 	 */
-	public function getBigIntTypeDeclarationSQL(array $column)
+	public function getBigIntTypeDeclarationSQL(array $column): string
 	{
 		return 'BIGINT';
 	}
@@ -60,7 +60,7 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritDoc}
 	 */
-	public function getSmallIntTypeDeclarationSQL(array $column)
+	public function getSmallIntTypeDeclarationSQL(array $column): string
 	{
 		return 'SMALLINT';
 	}
@@ -68,7 +68,7 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritDoc}
 	 */
-	public function getDefaultValueDeclarationSQL($column)
+	public function getDefaultValueDeclarationSQL($column): string
 	{
 		if ($this->isSerialColumn($column))
 		{
@@ -81,7 +81,7 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritDoc}
 	 */
-	public function supportsIdentityColumns()
+	public function supportsIdentityColumns(): bool
 	{
 		return false;
 	}
@@ -89,7 +89,7 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritDoc}
 	 */
-	protected function _getCreateTableSQL($name, array $columns, array $options = [])
+	protected function _getCreateTableSQL($name, array $columns, array $options = []): array
 	{
 		$sql = [];
 		$post_sql = [];
@@ -113,7 +113,9 @@ class postgresql_platform extends PostgreSQLPlatform
 	}
 
 	/**
-	 * @param array $column
+	 * Return if column is a "serial" column, i.e. type supporting auto-increment
+	 *
+	 * @param array $column Column data
 	 * @return bool
 	 */
 	private function isSerialColumn(array $column): bool
@@ -123,6 +125,12 @@ class postgresql_platform extends PostgreSQLPlatform
 			&& $this->isNumericType($column['type']);
 	}
 
+	/**
+	 * Return if supplied type is of numeric type
+	 *
+	 * @param Type $type
+	 * @return bool
+	 */
 	private function isNumericType(Type $type): bool
 	{
 		return $type instanceof IntegerType || $type instanceof BigIntType || $type instanceof SmallIntType;
@@ -131,21 +139,21 @@ class postgresql_platform extends PostgreSQLPlatform
 	/**
 	 * {@inheritDoc}
 	 */
-	public function getListSequencesSQL($database)
+	public function getListSequencesSQL($database): string
 	{
 		return "SELECT sequence_name AS relname,
-                       sequence_schema AS schemaname,
-                       1 AS min_value,
-                       1 AS increment_by
-                FROM   information_schema.sequences
-                WHERE  sequence_schema NOT LIKE 'pg\_%'
-                AND    sequence_schema <> 'information_schema'";
+				sequence_schema AS schemaname,
+				1 AS min_value,
+				1 AS increment_by
+			FROM information_schema.sequences
+			WHERE sequence_schema NOT LIKE 'pg\_%'
+				AND sequence_schema <> 'information_schema'";
 	}
 
 	/**
 	 * {@inheritDoc}
 	 */
-	public function getDropIndexSQL($index, $table = null)
+	public function getDropIndexSQL($index, $table = null): string
 	{
 		// If we have a primary or a unique index, we need to drop the constraint
 		// instead of the index itself or postgreSQL will reject the query.
diff --git a/phpBB/phpbb/db/doctrine/table_helper.php b/phpBB/phpbb/db/doctrine/table_helper.php
index 92f2069715..f6fde0fd2d 100644
--- a/phpBB/phpbb/db/doctrine/table_helper.php
+++ b/phpBB/phpbb/db/doctrine/table_helper.php
@@ -122,6 +122,9 @@ class table_helper
 		}
 	}
 
+	/**
+	 * Private constructor. Call methods of table_helper statically.
+	 */
 	private function __construct()
 	{
 	}
diff --git a/phpBB/phpbb/db/tools/doctrine.php b/phpBB/phpbb/db/tools/doctrine.php
index f242626f95..322cd8c16f 100644
--- a/phpBB/phpbb/db/tools/doctrine.php
+++ b/phpBB/phpbb/db/tools/doctrine.php
@@ -178,7 +178,7 @@ class doctrine implements tools_interface
 	{
 		if (empty($schema_changes))
 		{
-			return;
+			return true;
 		}
 
 		return $this->alter_schema(
@@ -668,7 +668,7 @@ class doctrine implements tools_interface
 			{
 				if ($safe_check && $table->hasColumn($column_name))
 				{
-					return;
+					return false;
 				}
 
 				$dbms_name = $this->get_schema_manager()->getDatabasePlatform()->getName();