From 80a3c54cfaa46c334617455dd6fa7f84d1f90e50 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Tue, 19 Nov 2024 13:47:18 +0100 Subject: [PATCH] Added strict types to the contracts --- .../AbstractFieldCriterionMapper.php | 5 +-- .../Values/Query/AbstractCriterionQuery.php | 2 +- .../Values/Query/AbstractSortClause.php | 4 +- .../Query/Criterion/FieldValueCriterion.php | 37 ++++++++----------- src/contracts/Values/Query/SortDirection.php | 4 +- 5 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/contracts/Persistence/CriterionMapper/AbstractFieldCriterionMapper.php b/src/contracts/Persistence/CriterionMapper/AbstractFieldCriterionMapper.php index b720e7e..be51286 100644 --- a/src/contracts/Persistence/CriterionMapper/AbstractFieldCriterionMapper.php +++ b/src/contracts/Persistence/CriterionMapper/AbstractFieldCriterionMapper.php @@ -79,10 +79,7 @@ protected function getComparisonOperator(FieldValueCriterion $criterion): string )); } - /** - * @return mixed - */ - protected function getComparisonValue(FieldValueCriterion $criterion) + protected function getComparisonValue(FieldValueCriterion $criterion): mixed { return $criterion->getValue(); } diff --git a/src/contracts/Values/Query/AbstractCriterionQuery.php b/src/contracts/Values/Query/AbstractCriterionQuery.php index 34c24dc..7e3d934 100644 --- a/src/contracts/Values/Query/AbstractCriterionQuery.php +++ b/src/contracts/Values/Query/AbstractCriterionQuery.php @@ -16,7 +16,7 @@ */ abstract class AbstractCriterionQuery { - public const DEFAULT_LIMIT = 25; + public const int DEFAULT_LIMIT = 25; /** @var TCriterion|null */ private ?CriterionInterface $query; diff --git a/src/contracts/Values/Query/AbstractSortClause.php b/src/contracts/Values/Query/AbstractSortClause.php index 2728e93..b80a628 100644 --- a/src/contracts/Values/Query/AbstractSortClause.php +++ b/src/contracts/Values/Query/AbstractSortClause.php @@ -13,10 +13,10 @@ abstract class AbstractSortClause { /** @final */ - public const SORT_ASC = SortDirection::ASC; + public const string SORT_ASC = SortDirection::ASC; /** @final */ - public const SORT_DESC = SortDirection::DESC; + public const string SORT_DESC = SortDirection::DESC; /** * Sort direction. diff --git a/src/contracts/Values/Query/Criterion/FieldValueCriterion.php b/src/contracts/Values/Query/Criterion/FieldValueCriterion.php index 54cdafa..c5ed860 100644 --- a/src/contracts/Values/Query/Criterion/FieldValueCriterion.php +++ b/src/contracts/Values/Query/Criterion/FieldValueCriterion.php @@ -11,34 +11,33 @@ class FieldValueCriterion implements CriterionInterface { /** @final */ - public const COMPARISON_EQ = '='; + public const string COMPARISON_EQ = '='; /** @final */ - public const COMPARISON_NEQ = '<>'; + public const string COMPARISON_NEQ = '<>'; /** @final */ - public const COMPARISON_LT = '<'; + public const string COMPARISON_LT = '<'; /** @final */ - public const COMPARISON_LTE = '<='; + public const string COMPARISON_LTE = '<='; /** @final */ - public const COMPARISON_GT = '>'; + public const string COMPARISON_GT = '>'; /** @final */ - public const COMPARISON_GTE = '>='; + public const string COMPARISON_GTE = '>='; /** @final */ - public const COMPARISON_IN = 'IN'; + public const string COMPARISON_IN = 'IN'; /** @final */ - public const COMPARISON_NIN = 'NIN'; + public const string COMPARISON_NIN = 'NIN'; /** @final */ - public const COMPARISON_CONTAINS = 'CONTAINS'; + public const string COMPARISON_CONTAINS = 'CONTAINS'; /** @final */ - public const COMPARISON_MEMBER_OF = 'MEMBER_OF'; + public const string COMPARISON_MEMBER_OF = 'MEMBER_OF'; /** @final */ - public const COMPARISON_STARTS_WITH = 'STARTS_WITH'; + public const string COMPARISON_STARTS_WITH = 'STARTS_WITH'; /** @final */ - public const COMPARISON_ENDS_WITH = 'ENDS_WITH'; + public const string COMPARISON_ENDS_WITH = 'ENDS_WITH'; private string $field; - /** @var mixed */ - private $value; + private mixed $value; private string $operator; @@ -57,18 +56,12 @@ public function getField(): string return $this->field; } - /** - * @param mixed $value - */ - public function setValue($value): void + public function setValue(mixed $value): void { $this->value = $value; } - /** - * @return mixed - */ - public function getValue() + public function getValue(): mixed { return $this->value; } diff --git a/src/contracts/Values/Query/SortDirection.php b/src/contracts/Values/Query/SortDirection.php index 20eb5bc..67dcb35 100644 --- a/src/contracts/Values/Query/SortDirection.php +++ b/src/contracts/Values/Query/SortDirection.php @@ -13,8 +13,8 @@ */ class SortDirection { - public const ASC = 'ascending'; - public const DESC = 'descending'; + public const string ASC = 'ascending'; + public const string DESC = 'descending'; /** * @phpstan-assert-if-true self::ASC|self::DESC $value