Skip to content

Commit

Permalink
Required PHP 8.4 (#313)
Browse files Browse the repository at this point in the history
* Started adding PHP 8.4 support

* Fixed CI to work with PHP 8.4

* Updated collections and console drivers to take advantage of property hooks

* Updated CI to use this branch's CI template

* Attempting to fix CI

* Updated CI to ignore platform requirements

* Fixed deprecations for implicit nullable types within Aphiria framework (still some within the PSR7 library Aphiria uses)

* Updated console output to use property for driver

* Made IMediaTypeFormatter use property hooks

* Updated streams to use property hooks

* Updated console AST nodes to use property hooks

* WIP: Updated HTTP request and response classes to use properties, still need to fix all the mocks

* Fixed all compiler errors, still need to update all mocks

* WIP: Updated all interfaces to use property hooks where applicable but have not updated mocks.  Also started updating classes to use property hooks

* Updated console classes to use property hooks

* Updated a few collection classes to use properties to return their values, clarified some session properties to be more self-descriptive

* Fixed a few typos

* Converted a few more protected methods to properties

* Updated remaining getter methods to properties as appropriate

* Fixed typo for user property in Controller

* Converted controller methods to properties backed by virtual properties

* Updated progress bar to use property to track progress

* Updated session setters to use properties, made names of methods and parameters around session variables more self-explanatory

* Updated error message interpolators to use properties, fixed setters with backing properties that use the abbreviated syntax

* Converted a few more session methods to properties

* Changed a few more boolean methods to be properties

* Started mocking properties the way they will be mocked in PHPUnit going forward (WIP)

* In a perfect world, everything should run once PHPUnit supports mocking property hooks

* Fixed PHPDoc for some constants

* Removed unneeded parantheses

* Minor code tweaks

* Updated to use experimental branch of PHPUnit that supports property hooks, started fixing tests

* Updated to use PropertyHook::get and ::set to mock properties

* Fixed some broken tests, still working through more

* Fixed a bunch of tests, still more to fix

* Got all tests running

* Fixed mock type

* Using temp PAT for Composer while referencing non-published branch of PHPUnit

* Fixed CI

* Trying to fix CI

* Trying to fix CI

* Trying to fix CI

* Fixed some tests

* Fixed some tests

* Fixed some tests

* Fixed nullable type

* Fixed typo

* Updated to use dev-main for PHPUnit

* Updated to PHPUnit 11.5

* Removed unnecessary steps from CI

* Fixed CI

* Removed Mockery mocks because they do not support properties in interfaces yet

* Updated PHP-Parser version
  • Loading branch information
davidbyoung authored Oct 20, 2024
1 parent 46abb29 commit 72a9672
Show file tree
Hide file tree
Showing 69 changed files with 238 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@license https://github.com/aphiria/aphiria/blob/1.x/LICENSE.md
EOT;

return (new PhpCsFixer\Config())
return new PhpCsFixer\Config()
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
"require": {
"aphiria/reflection": "1.x-dev",
"ext-intl": "*",
"php": "^8.3"
"php": "^8.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.5",
"phpunit/phpunit": "^10.1"
"phpunit/phpunit": "^11.5-dev"
},
"scripts": {
"phpcs-test": "@phpcs-fix --dry-run",
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Alpha extends ConstraintAttribute
/**
* @inheritdoc
*/
public function __construct(string $errorMessageId = null)
public function __construct(?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Alphanumeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Alphanumeric extends ConstraintAttribute
/**
* @inheritdoc
*/
public function __construct(string $errorMessageId = null)
public function __construct(?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
public readonly int|float $max,
public readonly bool $minIsInclusive = true,
public readonly bool $maxIsInclusive = true,
string $errorMessageId = null
?string $errorMessageId = null
) {
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class Date extends ConstraintAttribute
* @param list<string> $acceptableFormats The list of acceptable DateTime formats
* @throws InvalidArgumentException Thrown if there were no acceptable date formats
*/
public function __construct(public readonly array $acceptableFormats, string $errorMessageId = null)
public function __construct(public readonly array $acceptableFormats, ?string $errorMessageId = null)
{
parent::__construct($errorMessageId);

Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Each.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class Each extends ConstraintAttribute
* @param list<IConstraintAttribute> $constraints The list of constraint attributes that mucst be passed
* @throws InvalidArgumentException Thrown if the list of constraints is empty
*/
public function __construct(public readonly array $constraints, string $errorMessageId = null)
public function __construct(public readonly array $constraints, ?string $errorMessageId = null)
{
parent::__construct($errorMessageId);

Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Email extends ConstraintAttribute
/**
* @inheritdoc
*/
public function __construct(string $errorMessageId = null)
public function __construct(?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Equals.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Equals extends ConstraintAttribute
* @inheritdoc
* @param mixed $value The value to compare against
*/
public function __construct(public readonly mixed $value, string $errorMessageId = null)
public function __construct(public readonly mixed $value, ?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/IPAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class IPAddress extends ConstraintAttribute
/**
* @inheritdoc
*/
public function __construct(string $errorMessageId = null)
public function __construct(?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class In extends ConstraintAttribute
* @inheritdoc
* @param list<mixed> $values The values to check
*/
public function __construct(public readonly array $values, string $errorMessageId = null)
public function __construct(public readonly array $values, ?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Integer extends ConstraintAttribute
/**
* @inheritdoc
*/
public function __construct(string $errorMessageId = null)
public function __construct(?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class Max extends ConstraintAttribute
public function __construct(
public readonly int|float $max,
public bool $isInclusive = true,
string $errorMessageId = null
?string $errorMessageId = null
) {
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class Min extends ConstraintAttribute
public function __construct(
public readonly int|float $min,
public readonly bool $isInclusive = true,
string $errorMessageId = null
?string $errorMessageId = null
) {
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/NotIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class NotIn extends ConstraintAttribute
* @inheritdoc
* @param list<mixed> $values The values to check
*/
public function __construct(public readonly array $values, string $errorMessageId = null)
public function __construct(public readonly array $values, ?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Numeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Numeric extends ConstraintAttribute
/**
* @inheritdoc
*/
public function __construct(string $errorMessageId = null)
public function __construct(?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Regex extends ConstraintAttribute
* @inheritdoc
* @param string $regex The regex to apply
*/
public function __construct(public readonly string $regex, string $errorMessageId = null)
public function __construct(public readonly string $regex, ?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Constraints/Attributes/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Required extends ConstraintAttribute
/**
* @inheritdoc
*/
public function __construct(string $errorMessageId = null)
public function __construct(?string $errorMessageId = null)
{
parent::__construct($errorMessageId);
}
Expand Down
14 changes: 5 additions & 9 deletions src/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
*/
abstract class Constraint implements IConstraint
{
/**
* @param string $errorMessageId The ID of the error message associated with this constraint
*/
protected function __construct(protected readonly string $errorMessageId)
{
}
/** @@inheritdoc */
public protected(set) string $errorMessageId;

/**
* @inheritdoc
* @param string $errorMessageId The ID of the error message associated with this constraint
*/
public function getErrorMessageId(): string
protected function __construct(string $errorMessageId)
{
return $this->errorMessageId;
$this->errorMessageId = $errorMessageId;
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/Constraints/IConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
interface IConstraint
{
/**
* Gets the ID of the error message associated with this constraint
*
* @return string The error message ID
* @var string The error message ID
* @note If not supporting localization, this could contains the error message itself
*/
public function getErrorMessageId(): string;
public string $errorMessageId { get; }

/**
* Gets the values that can be used to compile error messages
Expand Down
28 changes: 4 additions & 24 deletions src/Constraints/ObjectConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
final class ObjectConstraints
{
/** @var array<string, list<IConstraint>> The mapping of method names to constraints */
private array $methodConstraints = [];
public private(set) array $methodConstraints = [];
/** @var array<string, list<IConstraint>> The mapping of property names to constraints */
private array $propertyConstraints = [];
public private(set) array $propertyConstraints = [];

/**
* @param class-string $className The name of the class whose constraints are represented here
Expand Down Expand Up @@ -63,33 +63,13 @@ public function addPropertyConstraint(string $propertyName, IConstraint|array $c
$this->propertyConstraints[$propertyName] = \is_array($constraint) ? $constraint : [$constraint];
}

/**
* Gets all the method constraints
*
* @return array<string, list<IConstraint>> The mapping of method names to constraints
*/
public function getAllMethodConstraints(): array
{
return $this->methodConstraints;
}

/**
* Gets all the property constraints
*
* @return array<string, list<IConstraint>> The mapping of property names to constraints
*/
public function getAllPropertyConstraints(): array
{
return $this->propertyConstraints;
}

/**
* Gets all constraints for a particular method
*
* @param string $methodName The name of the method whose constraints we want
* @return list<IConstraint> The list of constraints
*/
public function getMethodConstraints(string $methodName): array
public function getConstraintsForMethod(string $methodName): array
{
return $this->methodConstraints[$methodName] ?? [];
}
Expand All @@ -100,7 +80,7 @@ public function getMethodConstraints(string $methodName): array
* @param string $propertyName The name of the property whose constraints we want
* @return list<IConstraint> The list of constraints
*/
public function getPropertyConstraints(string $propertyName): array
public function getConstraintsForProperty(string $propertyName): array
{
return $this->propertyConstraints[$propertyName] ?? [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/ErrorMessages/DefaultErrorMessageTemplateRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class DefaultErrorMessageTemplateRegistry implements IErrorMessageTemplate
/**
* @inheritdoc
*/
public function getErrorMessageTemplate(string $errorMessageId, string $locale = null): string
public function getErrorMessageTemplate(string $errorMessageId, ?string $locale = null): string
{
return $errorMessageId;
}
Expand Down
16 changes: 8 additions & 8 deletions src/ErrorMessages/IErrorMessageInterpolator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
interface IErrorMessageInterpolator
{
/** @var string The default locale to use */
public string $defaultLocale { set; }

/**
* Interpolates an error message ID along with placeholders into human-readable error messages
*
Expand All @@ -26,12 +29,9 @@ interface IErrorMessageInterpolator
* @return string The interpolated error message
* @throws ErrorMessageInterpolationException Thrown if the error message could not be interpolated
*/
public function interpolate(string $errorMessageId, array $errorMessagePlaceholders = [], string $locale = null): string;

/**
* Sets the default locale
*
* @param string $locale The default locale to use
*/
public function setDefaultLocale(string $locale): void;
public function interpolate(
string $errorMessageId,
array $errorMessagePlaceholders = [],
?string $locale = null
): string;
}
2 changes: 1 addition & 1 deletion src/ErrorMessages/IErrorMessageTemplateRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ interface IErrorMessageTemplateRegistry
* @param string|null $locale The optional locale
* @return string The error message template
*/
public function getErrorMessageTemplate(string $errorMessageId, string $locale = null): string;
public function getErrorMessageTemplate(string $errorMessageId, ?string $locale = null): string;
}
27 changes: 14 additions & 13 deletions src/ErrorMessages/IcuFormatErrorMessageInterpolator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
*/
final class IcuFormatErrorMessageInterpolator implements IErrorMessageInterpolator
{
/** @inheritdoc */
public string $defaultLocale {
set {
$this->_defaultLocale = $value;
}
}
/** @var string The default locale, if none is specified */
private string $defaultLocale;
private string $_defaultLocale;

/**
* @param IErrorMessageTemplateRegistry $errorMessageTemplates The error message template registry to use
Expand All @@ -30,16 +36,19 @@ public function __construct(
private readonly IErrorMessageTemplateRegistry $errorMessageTemplates = new DefaultErrorMessageTemplateRegistry(),
string $defaultLocale = 'en'
) {
$this->setDefaultLocale($defaultLocale);
$this->defaultLocale = $defaultLocale;
}

/**
* @inheritdoc
*/
public function interpolate(string $errorMessageId, array $errorMessagePlaceholders = [], string $locale = null): string
{
public function interpolate(
string $errorMessageId,
array $errorMessagePlaceholders = [],
?string $locale = null
): string {
$interpolatedErrorMessage = MessageFormatter::formatMessage(
$locale ?? $this->defaultLocale,
$locale ?? $this->_defaultLocale,
$this->errorMessageTemplates->getErrorMessageTemplate($errorMessageId, $locale),
$errorMessagePlaceholders
);
Expand All @@ -50,12 +59,4 @@ public function interpolate(string $errorMessageId, array $errorMessagePlacehold

return $interpolatedErrorMessage;
}

/**
* @inheritdoc
*/
public function setDefaultLocale(string $locale): void
{
$this->defaultLocale = $locale;
}
}
Loading

0 comments on commit 72a9672

Please sign in to comment.