From a9df861b1b9418d66644cf9d984793f48d2040cf Mon Sep 17 00:00:00 2001 From: Simon Mundy Date: Tue, 17 Nov 2026 16:53:39 +1100 Subject: [PATCH] Make public constants final and type NAMED_ADAPTER_KEY Mark the 38 public constants that nothing in phpdb or the driver packages redeclares as final, so implementers and subclasses cannot override them. Since PHP 8.1 an implementing class can override an interface constant unless it is final. The SPECIFICATION_* constants on Insert, Update and Delete and HOLDS_MAPPED_ROWS stay overridable, since subclasses override them by design. ConfigProvider::NAMED_ADAPTER_KEY gains its missing string type, which clears its analyzer baseline entry. --- analyzer-baseline.toml | 6 ------ src/Adapter/AdapterInterface.php | 16 +++++++-------- src/Adapter/Driver/DriverInterface.php | 4 ++-- src/Adapter/Driver/Pdo/Result.php | 6 +++--- src/Adapter/ParameterContainer.php | 14 ++++++------- src/ConfigProvider.php | 2 +- src/Metadata/Source/AbstractSource.php | 2 +- src/ResultSet/ResultSet.php | 4 ++-- src/Sql/SqlInterface.php | 8 ++++---- .../Feature/EventFeatureEventsInterface.php | 20 +++++++++---------- src/TableGateway/Feature/FeatureSet.php | 2 +- 11 files changed, 39 insertions(+), 45 deletions(-) diff --git a/analyzer-baseline.toml b/analyzer-baseline.toml index 3e7637504..6525bc725 100644 --- a/analyzer-baseline.toml +++ b/analyzer-baseline.toml @@ -138,12 +138,6 @@ code = "imprecise-type" message = "Type `array` in return type of `getDependencies` is imprecise, equivalent to `array`." count = 1 -[[issues]] -file = "src/ConfigProvider.php" -code = "missing-constant-type" -message = "Class constant `NAMED_ADAPTER_KEY` is missing a type hint." -count = 1 - [[issues]] file = "src/Container/AbstractAdapterInterfaceFactory.php" code = "imprecise-type" diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 6935dbeb2..d9321f579 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -17,20 +17,20 @@ interface AdapterInterface /** * Query Mode Constants */ - public const string QUERY_MODE_EXECUTE = 'execute'; - public const string QUERY_MODE_PREPARE = 'prepare'; + final public const string QUERY_MODE_EXECUTE = 'execute'; + final public const string QUERY_MODE_PREPARE = 'prepare'; /** * Prepare Type Constants */ - public const string PREPARE_TYPE_POSITIONAL = 'positional'; - public const string PREPARE_TYPE_NAMED = 'named'; + final public const string PREPARE_TYPE_POSITIONAL = 'positional'; + final public const string PREPARE_TYPE_NAMED = 'named'; - public const string FUNCTION_FORMAT_PARAMETER_NAME = 'formatParameterName'; - public const string FUNCTION_QUOTE_IDENTIFIER = 'quoteIdentifier'; - public const string FUNCTION_QUOTE_VALUE = 'quoteValue'; + final public const string FUNCTION_FORMAT_PARAMETER_NAME = 'formatParameterName'; + final public const string FUNCTION_QUOTE_IDENTIFIER = 'quoteIdentifier'; + final public const string FUNCTION_QUOTE_VALUE = 'quoteValue'; - public const string VALUE_QUOTE_SEPARATOR = 'quoteSeparator'; + final public const string VALUE_QUOTE_SEPARATOR = 'quoteSeparator'; /** * @param ParameterContainer|array $initialParameters diff --git a/src/Adapter/Driver/DriverInterface.php b/src/Adapter/Driver/DriverInterface.php index e5007c146..dff8bcbb8 100644 --- a/src/Adapter/Driver/DriverInterface.php +++ b/src/Adapter/Driver/DriverInterface.php @@ -11,8 +11,8 @@ */ interface DriverInterface { - public const string PARAMETERIZATION_POSITIONAL = 'positional'; - public const string PARAMETERIZATION_NAMED = 'named'; + final public const string PARAMETERIZATION_POSITIONAL = 'positional'; + final public const string PARAMETERIZATION_NAMED = 'named'; /** * Check environment diff --git a/src/Adapter/Driver/Pdo/Result.php b/src/Adapter/Driver/Pdo/Result.php index 84f078fa3..37a075050 100644 --- a/src/Adapter/Driver/Pdo/Result.php +++ b/src/Adapter/Driver/Pdo/Result.php @@ -28,8 +28,8 @@ */ class Result implements Iterator, ResultInterface { - public const string STATEMENT_MODE_SCROLLABLE = 'scrollable'; - public const string STATEMENT_MODE_FORWARD = 'forward'; + final public const string STATEMENT_MODE_SCROLLABLE = 'scrollable'; + final public const string STATEMENT_MODE_FORWARD = 'forward'; protected string $statementMode = self::STATEMENT_MODE_FORWARD; @@ -41,7 +41,7 @@ class Result implements Iterator, ResultInterface * * @var list */ - public const array VALID_FETCH_MODES = [ + final public const array VALID_FETCH_MODES = [ PDO::FETCH_LAZY, // 1 PDO::FETCH_ASSOC, // 2 PDO::FETCH_NUM, // 3 diff --git a/src/Adapter/ParameterContainer.php b/src/Adapter/ParameterContainer.php index 7372afdee..e9129797e 100644 --- a/src/Adapter/ParameterContainer.php +++ b/src/Adapter/ParameterContainer.php @@ -32,13 +32,13 @@ */ class ParameterContainer implements Iterator, ArrayAccess, Countable { - public const string TYPE_AUTO = 'auto'; - public const string TYPE_NULL = 'null'; - public const string TYPE_DOUBLE = 'double'; - public const string TYPE_INTEGER = 'integer'; - public const string TYPE_BINARY = 'binary'; - public const string TYPE_STRING = 'string'; - public const string TYPE_LOB = 'lob'; + final public const string TYPE_AUTO = 'auto'; + final public const string TYPE_NULL = 'null'; + final public const string TYPE_DOUBLE = 'double'; + final public const string TYPE_INTEGER = 'integer'; + final public const string TYPE_BINARY = 'binary'; + final public const string TYPE_STRING = 'string'; + final public const string TYPE_LOB = 'lob'; /** * Data diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 80febb9e7..05942a274 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -6,7 +6,7 @@ final readonly class ConfigProvider { - public const NAMED_ADAPTER_KEY = 'adapters'; + public const string NAMED_ADAPTER_KEY = 'adapters'; public function getDependencies(): array { diff --git a/src/Metadata/Source/AbstractSource.php b/src/Metadata/Source/AbstractSource.php index e91ebdedd..3c08c5b71 100644 --- a/src/Metadata/Source/AbstractSource.php +++ b/src/Metadata/Source/AbstractSource.php @@ -98,7 +98,7 @@ */ abstract class AbstractSource implements MetadataInterface { - public const string DEFAULT_SCHEMA = '__DEFAULT_SCHEMA__'; + final public const string DEFAULT_SCHEMA = '__DEFAULT_SCHEMA__'; protected string $defaultSchema; diff --git a/src/ResultSet/ResultSet.php b/src/ResultSet/ResultSet.php index 78ee864c1..5626641b3 100644 --- a/src/ResultSet/ResultSet.php +++ b/src/ResultSet/ResultSet.php @@ -18,8 +18,8 @@ class ResultSet extends AbstractResultSet implements ArrayObjectResultSetInterface { /** @deprecated use ResultSetReturnType */ - public const string TYPE_ARRAYOBJECT = 'arrayobject'; - public const string TYPE_ARRAY = 'array'; + final public const string TYPE_ARRAYOBJECT = 'arrayobject'; + final public const string TYPE_ARRAY = 'array'; private readonly ResultSetReturnType $returnType; diff --git a/src/Sql/SqlInterface.php b/src/Sql/SqlInterface.php index 433ed032b..082238126 100644 --- a/src/Sql/SqlInterface.php +++ b/src/Sql/SqlInterface.php @@ -18,13 +18,13 @@ interface SqlInterface * * @see ArgumentType */ - public const string TYPE_IDENTIFIER = 'identifier'; + final public const string TYPE_IDENTIFIER = 'identifier'; - public const string TYPE_VALUE = 'value'; + final public const string TYPE_VALUE = 'value'; - public const string TYPE_LITERAL = 'literal'; + final public const string TYPE_LITERAL = 'literal'; - public const string TYPE_SELECT = 'select'; + final public const string TYPE_SELECT = 'select'; /** * Get SQL string for statement diff --git a/src/TableGateway/Feature/EventFeatureEventsInterface.php b/src/TableGateway/Feature/EventFeatureEventsInterface.php index 26778c4be..1985c065f 100644 --- a/src/TableGateway/Feature/EventFeatureEventsInterface.php +++ b/src/TableGateway/Feature/EventFeatureEventsInterface.php @@ -16,18 +16,18 @@ */ interface EventFeatureEventsInterface { - public const string EVENT_PRE_INITIALIZE = 'preInitialize'; - public const string EVENT_POST_INITIALIZE = 'postInitialize'; + final public const string EVENT_PRE_INITIALIZE = 'preInitialize'; + final public const string EVENT_POST_INITIALIZE = 'postInitialize'; - public const string EVENT_PRE_SELECT = 'preSelect'; - public const string EVENT_POST_SELECT = 'postSelect'; + final public const string EVENT_PRE_SELECT = 'preSelect'; + final public const string EVENT_POST_SELECT = 'postSelect'; - public const string EVENT_PRE_INSERT = 'preInsert'; - public const string EVENT_POST_INSERT = 'postInsert'; + final public const string EVENT_PRE_INSERT = 'preInsert'; + final public const string EVENT_POST_INSERT = 'postInsert'; - public const string EVENT_PRE_DELETE = 'preDelete'; - public const string EVENT_POST_DELETE = 'postDelete'; + final public const string EVENT_PRE_DELETE = 'preDelete'; + final public const string EVENT_POST_DELETE = 'postDelete'; - public const string EVENT_PRE_UPDATE = 'preUpdate'; - public const string EVENT_POST_UPDATE = 'postUpdate'; + final public const string EVENT_PRE_UPDATE = 'preUpdate'; + final public const string EVENT_POST_UPDATE = 'postUpdate'; } diff --git a/src/TableGateway/Feature/FeatureSet.php b/src/TableGateway/Feature/FeatureSet.php index 01c5c8d80..54d81bb0e 100644 --- a/src/TableGateway/Feature/FeatureSet.php +++ b/src/TableGateway/Feature/FeatureSet.php @@ -14,7 +14,7 @@ */ class FeatureSet { - public const string APPLY_HALT = 'halt'; + final public const string APPLY_HALT = 'halt'; protected ?AbstractTableGateway $tableGateway = null;