From 1cb89cbfeaf46e04b721cbad98c1267b32dc39d4 Mon Sep 17 00:00:00 2001 From: Simon Mundy Date: Tue, 29 Sep 2026 15:37:50 +1000 Subject: [PATCH] Bring Metadata, Exception and Feature to full Mago compliance Declares the constant types Mago asks for on the ConstraintKeyObject foreign key actions and on AbstractSource::DEFAULT_SCHEMA. Typed constants need PHP 8.3, which is the floor, and EventFeatureEventsInterface already uses them. The three root exception classes import their parent under a Base alias rather than naming it fully qualified. A plain import is not available: each class shadows the name of the class it extends. ExceptionInterface is marked @api, matching the fourteen files that already carry the tag. The two Metadata exception classes are marked final. Nothing subclasses them. The remaining exception classes are left alone, so the convention is mixed until each component is visited. Feature was already clean. All three components now leave both baselines entirely: lint falls to 345 and the analyzer to 1206. --- analyzer-baseline.toml | 54 ------------------- lint-baseline.toml | 18 ------- src/Exception/ExceptionInterface.php | 6 ++- src/Exception/InvalidArgumentException.php | 4 +- src/Exception/RuntimeException.php | 4 +- src/Exception/UnexpectedValueException.php | 4 +- .../Exception/InvalidArgumentException.php | 2 +- src/Metadata/Exception/RuntimeException.php | 2 +- src/Metadata/Object/ConstraintKeyObject.php | 10 ++-- src/Metadata/Source/AbstractSource.php | 2 +- 10 files changed, 22 insertions(+), 84 deletions(-) diff --git a/analyzer-baseline.toml b/analyzer-baseline.toml index e17bd353..1e794e9e 100644 --- a/analyzer-baseline.toml +++ b/analyzer-baseline.toml @@ -1446,60 +1446,6 @@ code = "unhandled-thrown-type" message = 'Potentially unhandled exception `Psr\Container\NotFoundExceptionInterface` in `PhpDb\Container\AdapterInterfaceFactory::__invoke`.' count = 1 -[[issues]] -file = "src/Exception/ExceptionInterface.php" -code = "missing-api-or-internal" -message = 'Interface `PhpDb\Exception\ExceptionInterface` is missing an `@api` or `@internal` annotation.' -count = 1 - -[[issues]] -file = "src/Metadata/Exception/InvalidArgumentException.php" -code = "class-must-be-final" -message = 'Class `PhpDb\Metadata\Exception\InvalidArgumentException` should be declared `final`.' -count = 1 - -[[issues]] -file = "src/Metadata/Exception/RuntimeException.php" -code = "class-must-be-final" -message = 'Class `PhpDb\Metadata\Exception\RuntimeException` should be declared `final`.' -count = 1 - -[[issues]] -file = "src/Metadata/Object/ConstraintKeyObject.php" -code = "missing-constant-type" -message = "Class constant `FK_CASCADE` is missing a type hint." -count = 1 - -[[issues]] -file = "src/Metadata/Object/ConstraintKeyObject.php" -code = "missing-constant-type" -message = "Class constant `FK_NO_ACTION` is missing a type hint." -count = 1 - -[[issues]] -file = "src/Metadata/Object/ConstraintKeyObject.php" -code = "missing-constant-type" -message = "Class constant `FK_RESTRICT` is missing a type hint." -count = 1 - -[[issues]] -file = "src/Metadata/Object/ConstraintKeyObject.php" -code = "missing-constant-type" -message = "Class constant `FK_SET_DEFAULT` is missing a type hint." -count = 1 - -[[issues]] -file = "src/Metadata/Object/ConstraintKeyObject.php" -code = "missing-constant-type" -message = "Class constant `FK_SET_NULL` is missing a type hint." -count = 1 - -[[issues]] -file = "src/Metadata/Source/AbstractSource.php" -code = "missing-constant-type" -message = "Class constant `DEFAULT_SCHEMA` is missing a type hint." -count = 1 - [[issues]] file = "src/ResultSet/AbstractResultSet.php" code = "imprecise-type" diff --git a/lint-baseline.toml b/lint-baseline.toml index a167d2d1..3b7ac868 100644 --- a/lint-baseline.toml +++ b/lint-baseline.toml @@ -228,24 +228,6 @@ code = "no-isset" message = "Use of the `isset` construct." count = 1 -[[issues]] -file = "src/Exception/InvalidArgumentException.php" -code = "no-fully-qualified-global-class-like" -message = "Fully-qualified class-like reference detected." -count = 1 - -[[issues]] -file = "src/Exception/RuntimeException.php" -code = "no-fully-qualified-global-class-like" -message = "Fully-qualified class-like reference detected." -count = 1 - -[[issues]] -file = "src/Exception/UnexpectedValueException.php" -code = "no-fully-qualified-global-class-like" -message = "Fully-qualified class-like reference detected." -count = 1 - [[issues]] file = "src/ResultSet/AbstractResultSet.php" code = "cyclomatic-complexity" diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 5aac64ea..c3376717 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -6,5 +6,9 @@ use Throwable; -/** Marker for every exception this package throws. */ +/** + * Marker for every exception this package throws. + * + * @api + */ interface ExceptionInterface extends Throwable {} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index dfd9f705..f828615d 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -4,4 +4,6 @@ namespace PhpDb\Exception; -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface {} +use InvalidArgumentException as BaseInvalidArgumentException; + +class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface {} diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 76060619..50cac487 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -4,4 +4,6 @@ namespace PhpDb\Exception; -class RuntimeException extends \RuntimeException implements ExceptionInterface {} +use RuntimeException as BaseRuntimeException; + +class RuntimeException extends BaseRuntimeException implements ExceptionInterface {} diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php index c281897b..578534f8 100644 --- a/src/Exception/UnexpectedValueException.php +++ b/src/Exception/UnexpectedValueException.php @@ -4,4 +4,6 @@ namespace PhpDb\Exception; -class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface {} +use UnexpectedValueException as BaseUnexpectedValueException; + +class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface {} diff --git a/src/Metadata/Exception/InvalidArgumentException.php b/src/Metadata/Exception/InvalidArgumentException.php index 6fdac4db..4a97d1e8 100644 --- a/src/Metadata/Exception/InvalidArgumentException.php +++ b/src/Metadata/Exception/InvalidArgumentException.php @@ -6,4 +6,4 @@ use PhpDb\Exception; -class InvalidArgumentException extends Exception\InvalidArgumentException {} +final class InvalidArgumentException extends Exception\InvalidArgumentException {} diff --git a/src/Metadata/Exception/RuntimeException.php b/src/Metadata/Exception/RuntimeException.php index b814fb3e..b05595d8 100644 --- a/src/Metadata/Exception/RuntimeException.php +++ b/src/Metadata/Exception/RuntimeException.php @@ -8,7 +8,7 @@ use function sprintf; -class RuntimeException extends Exception\RuntimeException +final class RuntimeException extends Exception\RuntimeException { final public const string UNKNOWN_COLUMN = 'A column by that name was not found.'; diff --git a/src/Metadata/Object/ConstraintKeyObject.php b/src/Metadata/Object/ConstraintKeyObject.php index 973e3de3..191ad709 100644 --- a/src/Metadata/Object/ConstraintKeyObject.php +++ b/src/Metadata/Object/ConstraintKeyObject.php @@ -6,15 +6,15 @@ final class ConstraintKeyObject { - final public const FK_CASCADE = 'CASCADE'; + final public const string FK_CASCADE = 'CASCADE'; - final public const FK_SET_NULL = 'SET NULL'; + final public const string FK_SET_NULL = 'SET NULL'; - final public const FK_NO_ACTION = 'NO ACTION'; + final public const string FK_NO_ACTION = 'NO ACTION'; - final public const FK_RESTRICT = 'RESTRICT'; + final public const string FK_RESTRICT = 'RESTRICT'; - final public const FK_SET_DEFAULT = 'SET DEFAULT'; + final public const string FK_SET_DEFAULT = 'SET DEFAULT'; private ?int $ordinalPosition = null; diff --git a/src/Metadata/Source/AbstractSource.php b/src/Metadata/Source/AbstractSource.php index 6a994f90..3638d561 100644 --- a/src/Metadata/Source/AbstractSource.php +++ b/src/Metadata/Source/AbstractSource.php @@ -98,7 +98,7 @@ */ abstract class AbstractSource implements MetadataInterface { - public const DEFAULT_SCHEMA = '__DEFAULT_SCHEMA__'; + public const string DEFAULT_SCHEMA = '__DEFAULT_SCHEMA__'; protected string $defaultSchema;