Skip to content

Commit

Permalink
Test against PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 16, 2024
1 parent 6733c89 commit 662ffc3
Show file tree
Hide file tree
Showing 30 changed files with 83 additions and 72 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
php-version:
- "8.2"
- "8.3"
- "8.4"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ ARG PHP_VERSION=8.2
FROM php:${PHP_VERSION}-cli-bookworm

RUN <<-EOF
apt-get update
apt-get install -y autoconf pkg-config
pecl channel-update pecl.php.net
pecl install xdebug
docker-php-ext-enable opcache xdebug
docker-php-ext-enable opcache

if [ "$PHP_VERSION" \< "8.4" ]; then
apt-get update
apt-get install -y autoconf pkg-config
pecl channel-update pecl.php.net
pecl install xdebug
docker-php-ext-enable xdebug
fi
EOF

RUN <<-EOF
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ test-container-83:
@-docker-compose run --rm app83 bash
@docker-compose down -v

.PHONY: test-container-84
test-container-84:
@-docker-compose run --rm app84 bash
@docker-compose down -v

.PHONY: lint
lint:
@XDEBUG_MODE=off phpcs -s
Expand Down
20 changes: 13 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
context: .
args:
PHP_VERSION: "8.2"
environment:
environment: &env
PHP_IDE_CONFIG: 'serverName=icanboogie-activerecord'
volumes:
volumes: &vol
- .:/app:delegated
- ~/.composer:/root/.composer:delegated
working_dir: /app
Expand All @@ -16,9 +16,15 @@ services:
context: .
args:
PHP_VERSION: "8.3"
environment:
PHP_IDE_CONFIG: 'serverName=icanboogie-activerecord'
volumes:
- .:/app:delegated
- ~/.composer:/root/.composer:delegated
environment: *env
volumes: *vol
working_dir: /app
app84:
build:
context: .
dockerfile: Dockerfile
args:
PHP_VERSION: '8.4.0RC4'
environment: *env
volumes: *vol
working_dir: /app
2 changes: 1 addition & 1 deletion lib/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function get_primary_key_value(): mixed
* The model managing the active record. A {@link Model} instance can be specified as well as a model
* identifier. If `$model` is null, the model will be resolved with {@link StaticModelProvider} when required.
*/
public function __construct(Model $model = null)
public function __construct(?Model $model = null)
{
if ($model) {
$this->model = $model;
Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/ActiveRecordClassNotValid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ActiveRecordClassNotValid extends LogicException implements Exception
{
public function __construct(
public readonly string $class,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
parent::__construct($message ?? $this->format_message($class), previous: $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/Config/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function extends_model(string $value): void
or throw new LogicException("'$value' is not extending " . Model::class);
}

public static function extends_activerecord(string $value, string $message = null): void
public static function extends_activerecord(string $value, ?string $message = null): void
{
is_subclass_of($value, ActiveRecord::class)
or throw new LogicException($message ?? "'$value' is not extending " . ActiveRecord::class);
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Config/AssociationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function build(): TransientAssociation
*/
public function has_many(
string $associate,
string $foreign_key = null,
string $as = null,
string $through = null,
?string $foreign_key = null,
?string $as = null,
?string $through = null,
): self {
$this->has_many[] = new TransientHasManyAssociation(
associate: $associate,
Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ public function add_record(
string $query_class = Query::class,
?string $table_name = null,
?string $alias = null,
Closure $schema_builder = null,
Closure $association_builder = null,
?Closure $schema_builder = null,
?Closure $association_builder = null,
string $connection = Config::DEFAULT_CONNECTION_ID,
): self {
Assert::extends_activerecord($record_class);
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public function quote_identifier(string $identifier): string
return $this->driver->quote_identifier($identifier);
}

public function cast_value(mixed $value, string $type = null): mixed
public function cast_value(mixed $value, ?string $type = null): mixed
{
return $this->driver->cast_value($value, $type);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/ConnectionNotEstablished.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ConnectionNotEstablished extends RuntimeException implements Exception
public function __construct(
public readonly string $id,
string $message,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, previous: $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function quote_identifier(string $identifier): string;
*
* @param string|null $type One of `SchemaColumn::TYPE_*`.
*/
public function cast_value(mixed $value, string $type = null): int|string|null;
public function cast_value(mixed $value, ?string $type = null): int|string|null;

/**
* Creates a table given a schema.
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/Driver/BasicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function quote_identifier(string $identifier): string
/**
* @inheritDoc
*/
public function cast_value(mixed $value, string $type = null): int|string|null
public function cast_value(mixed $value, ?string $type = null): int|string|null
{
if ($value instanceof DateTimeInterface) {
return DateTime::from($value)->utc->as_db;
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/DriverNotDefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class DriverNotDefined extends LogicException implements Exception
*/
public function __construct(
public readonly string $driver_name,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
parent::__construct($message ?? $this->format_message($driver_name), 0, $previous);
parent::__construct($message ?? $this->format_message($driver_name), previous: $previous);
}

private function format_message(string $driver_name): string
Expand Down
24 changes: 12 additions & 12 deletions lib/ActiveRecord/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ public function select(string $expression): static
* </pre>
*/
public function join(
string $expression = null,
Query $query = null,
string $with = null,
?string $expression = null,
?Query $query = null,
?string $with = null,
string $mode = 'INNER',
string $as = null,
string $on = null,
?string $as = null,
?string $on = null,
): static {
if ($expression) {
$this->joins[] = $expression;
Expand Down Expand Up @@ -462,8 +462,8 @@ public function join(
private function join_with_query(
Query $query,
string $mode = 'INNER',
string $as = null,
string $on = null,
?string $as = null,
?string $on = null,
): void {
$as ??= $query->model->alias;
$on ??= $query->model->primary;
Expand Down Expand Up @@ -496,8 +496,8 @@ private function join_with_query(
private function join_with_model( // @phpstan-ignore-line
Model $model,
string $mode = 'INNER',
string $as = null,
string $on = null,
?string $as = null,
?string $on = null,
): void {
$as ??= $model->alias;
//phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
Expand Down Expand Up @@ -1001,7 +1001,7 @@ protected function get_exists(): bool
*
* @return string|array<string, string>
*/
private function compute(string $method, string $column = null): string|array
private function compute(string $method, ?string $column = null): string|array
{
$query = 'SELECT ';

Expand Down Expand Up @@ -1035,7 +1035,7 @@ private function compute(string $method, string $column = null): string|array
*
* @return int|array<non-empty-string, int>
*/
public function count(string $column = null): int|array
public function count(?string $column = null): int|array
{
// @phpstan-ignore-next-line
return $this->compute('COUNT', $column);
Expand Down Expand Up @@ -1105,7 +1105,7 @@ public function sum(string $column): int
* @todo-20140901: reflect on join to add the required tables by default, discarding tables
* joined with the LEFT mode.
*/
public function delete(string $tables = null): Statement
public function delete(?string $tables = null): Statement
{
if (!$tables && $this->joins) {
$tables = "`{alias}`";
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/RecordNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RecordNotFound extends LogicException implements Exception
public function __construct(
string $message,
public readonly array $records = [],
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, previous: $previous);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/ActiveRecord/RecordNotValid.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RecordNotValid extends LogicException implements Exception
public function __construct(
public readonly ActiveRecord $record,
public readonly ValidationErrors $errors,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($this->format_message($errors), previous: $previous);
}
Expand All @@ -27,9 +27,7 @@ private function format_message(ValidationErrors $errors): string
$message = self::DEFAULT_MESSAGE . "\n";

foreach ($errors as $attribute => $attribute_errors) {
// @phpstan-ignore-next-line
foreach ($attribute_errors as $error) {
// @phpstan-ignore-next-line
$message .= "\n- $attribute: $error";
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/Schema/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ public static function __set_state(array $an_array): self
* Values are signed by default.
* @param bool $serial
* An integer that is automatically incremented by the database. This has a few constraints:
* - `$size` must at least 2 bytes
* - `$size` must be at least two bytes
* - `$unsigned` must be `true`
* - `$null` must be `false`
* - `$unique` must be `true`
* Values are not serial by default.
* Values aren't serial by default.
*/
public function __construct(
public int $size = self::SIZE_REGULAR,
public bool $unsigned = false,
public bool $serial = false,
bool $null = false,
bool $unique = false,
int|string $default = null,
int|string|null $default = null,
) {
in_array($size, self::ALLOWED_SIZES)
or throw new LogicException("Size must be one of the allowed ones");
Expand Down
6 changes: 3 additions & 3 deletions lib/ActiveRecord/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function add_integer(
bool $serial = false,
bool $null = false,
bool $unique = false,
int|string $default = null,
int|string|null $default = null,
bool $primary = false,
): self {
$this->columns[$col_name] = new Integer(
Expand Down Expand Up @@ -401,9 +401,9 @@ public function add_text(
string $col_name,
string $size = Text::SIZE_REGULAR,
bool $null = false,
string $default = null,
?string $default = null,
bool $unique = false,
string $collate = null,
?string $collate = null,
): self {
$this->columns[$col_name] = new Text(
size: $size,
Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/ScopeNotDefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ScopeNotDefined extends LogicException implements Exception
public function __construct(
public readonly string $scope_name,
public readonly Model $model,
Throwable $previous = null
?Throwable $previous = null,
) {
parent::__construct($this->format_message($scope_name, $model), 0, $previous);
parent::__construct($this->format_message($scope_name, $model), previous: $previous);
}

private function format_message(string $scope_name, Model $model): string
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function execute(array $params = []): void
*
* @see PDOStatement::setFetchMode()
*/
public function mode(int $mode, string $class_name = null, mixed ...$params): self
public function mode(int $mode, ?string $class_name = null, mixed ...$params): self
{
// @phpstan-ignore-next-line
$this->pdo_statement->setFetchMode(...func_get_args())
Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/StatementInvocationFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class StatementInvocationFailed extends LogicException implements Exception
public function __construct(
public readonly Statement $statement,
public readonly array $args,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
parent::__construct($message ?? $this->format_message($statement, $args), previous: $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/StatementNotValid.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
/**
* @param array<mixed> $args
*/
private function format_message(string $statement, array $args, PDOException $original = null): string
private function format_message(string $statement, array $args, ?PDOException $original = null): string
{
$message = '';

Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private function filter_values(array $values, bool $extended = false): array
*
* @throws Throwable
*/
public function save(array $values, int $id = null, array $options = []): int|false
public function save(array $values, ?int $id = null, array $options = []): int|false
{
// TODO: If we have a parent, we should do the changes in a transaction.

Expand All @@ -298,7 +298,7 @@ public function save(array $values, int $id = null, array $options = []): int|fa
* @param array<string, mixed> $values
* @param array<string, mixed> $options
*/
private function save_callback(array $values, int $id = null, array $options = []): int
private function save_callback(array $values, ?int $id = null, array $options = []): int
{
assert(count($values) > 0);

Expand Down
4 changes: 2 additions & 2 deletions lib/ActiveRecord/UnableToSetFetchMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class UnableToSetFetchMode extends RuntimeException implements Exception
*/
public function __construct(
public readonly array $mode,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
parent::__construct($message ?? $this->format_message($mode), previous: $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ActiveRecord/Validate/Reader/RecordAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(ActiveRecord $source)
/**
* @inheritdoc
*/
public function read($name)
public function read(string $name): mixed
{
try {
return $this->source->$name;
Expand Down
Loading

0 comments on commit 662ffc3

Please sign in to comment.