Skip to content

Commit

Permalink
Support PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 1, 2024
1 parent 381fabc commit b731caa
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "8.1"
php-version: "8.3"
ini-values: memory_limit=-1
tools: phpcs, cs2pr
- name: Run PHP Code Sniffer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
php-version: "8.3"
ini-values: memory_limit=-1
tools: composer:v2
- name: Cache dependencies
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -40,7 +41,7 @@ jobs:
run: make test-coveralls

- name: Upload code coverage
if: ${{ matrix.php-version == '8.1' }}
if: ${{ matrix.php-version == '8.3' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.phpunit.cache
.phpunit.result.cache
build
composer.lock
vendor
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
ARG PHP_VERSION
ARG PHP_VERSION=8.2
FROM php:${PHP_VERSION}-cli-bookworm

RUN <<-EOF
docker-php-ext-enable opcache

PHP_VERSION=$(php -v | grep -oP '(?<=PHP )\d+\.\d+')

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 opcache xdebug
docker-php-ext-enable xdebug
fi
EOF

RUN <<-EOF
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# customization

PACKAGE_NAME = icanboogie/common
PHPUNIT = vendor/bin/phpunit

# do not edit the following lines

.PHONY: usage
usage:
@echo "test: Runs the test suite.\ndoc: Creates the documentation.\nclean: Removes the documentation, the dependencies and the Composer files."

vendor:
@composer install

Expand Down Expand Up @@ -49,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
11 changes: 11 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ services:
- .:/app:delegated
- ~/.composer:/root/.composer:delegated
working_dir: /app
app84:
build:
context: .
args:
PHP_VERSION: "8.4.0RC3"
environment:
PHP_IDE_CONFIG: 'serverName=icanboogie-common'
volumes:
- .:/app:delegated
- ~/.composer:/root/.composer:delegated
working_dir: /app
13 changes: 2 additions & 11 deletions lib/OffsetNotDefined.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand All @@ -27,8 +18,8 @@ class OffsetNotDefined extends LogicException implements OffsetError
public function __construct(
public readonly string|int $offset,
public readonly array|object|null $container = null,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
if (!$message) {
if (is_object($container)) {
Expand Down
13 changes: 2 additions & 11 deletions lib/OffsetNotReadable.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand All @@ -25,8 +16,8 @@ class OffsetNotReadable extends LogicException implements OffsetError
public function __construct(
public readonly string|int $offset,
public readonly array|object|null $container = null,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
if (!$message) {
if (is_object($container)) {
Expand Down
13 changes: 2 additions & 11 deletions lib/OffsetNotWritable.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand All @@ -25,8 +16,8 @@ class OffsetNotWritable extends LogicException implements OffsetError
public function __construct(
public readonly string|int $offset,
public readonly array|object|null $container = null,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
if (!$message) {
if (is_object($container)) {
Expand Down
9 changes: 0 additions & 9 deletions lib/PropertyError.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use Throwable;
Expand Down
11 changes: 1 addition & 10 deletions lib/PropertyIsReserved.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand All @@ -23,7 +14,7 @@ class PropertyIsReserved extends LogicException implements PropertyError
{
public function __construct(
public readonly string $property,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct(
"Property '$property' is reserved",
Expand Down
13 changes: 2 additions & 11 deletions lib/PropertyNotDefined.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand All @@ -24,8 +15,8 @@ class PropertyNotDefined extends LogicException implements PropertyError
public function __construct(
public readonly string $property,
public readonly object $container,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
$message ??= sprintf(
"Undefined property '%s' for object of class '%s'",
Expand Down
13 changes: 2 additions & 11 deletions lib/PropertyNotReadable.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand All @@ -24,8 +15,8 @@ class PropertyNotReadable extends LogicException implements PropertyError
public function __construct(
public readonly string $property,
public readonly object $container,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
$message ??= sprintf(
"The property '%s' for object of class '%s is not readable.",
Expand Down
13 changes: 2 additions & 11 deletions lib/PropertyNotWritable.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie;

use LogicException;
Expand All @@ -24,8 +15,8 @@ class PropertyNotWritable extends LogicException implements PropertyError
public function __construct(
public readonly string $property,
public readonly object $container,
string $message = null,
Throwable $previous = null
?string $message = null,
?Throwable $previous = null
) {
$message ??= sprintf(
"The property '%s' for object of class '%s' is not writable",
Expand Down
11 changes: 8 additions & 3 deletions lib/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @deprecated Sorting has been stable since PHP 8.0 https://wiki.php.net/rfc/stable_sorting
*/
function stable_sort(array &$array, callable $picker = null): void
function stable_sort(array &$array, ?callable $picker = null): void
{
@trigger_error('icanboogie/common: stable_sort() is deprecated, use asort() or uasort()', E_USER_DEPRECATED);

Expand Down Expand Up @@ -140,8 +140,13 @@ function sort_by_weight(array $array, callable $weight_picker): array
*
* @return array<int|string, mixed>
*/
function array_insert(array $array, mixed $relative, mixed $value, string|int $key = null, bool $after = false): array
{
function array_insert(
array $array,
mixed $relative,
mixed $value,
string|int|null $key = null,
bool $after = false
): array {
if ($key) {
unset($array[$key]);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/string.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* HTML special characters are escaped using the {@link htmlspecialchars()} function with the
* {@link ENT_COMPAT} flag.
*/
function escape(string $str, string $encoding = null): string
function escape(string $str, ?string $encoding = null): string
{
return htmlspecialchars($str, ENT_COMPAT, $encoding);
}
Expand All @@ -68,7 +68,7 @@ function escape(string $str, string $encoding = null): string
*
* Applicable characters are escaped using the {@link htmlentities()} function with the {@link ENT_COMPAT} flag.
*/
function escape_all(string $str, string $encoding = null): string
function escape_all(string $str, ?string $encoding = null): string
{
return htmlentities($str, ENT_COMPAT, $encoding);
}
Expand Down Expand Up @@ -123,7 +123,7 @@ function capitalize(string $str, bool $preserve_str_end = false): string
* @param float $position Position at which characters can be removed.
* @param bool $shortened `true` if the string was shortened, `false` otherwise.
*/
function shorten(string $str, int $length = 32, float $position = .75, bool &$shortened = null): string
function shorten(string $str, int $length = 32, float $position = .75, ?bool &$shortened = null): string
{
$l = mb_strlen($str);

Expand Down Expand Up @@ -152,7 +152,7 @@ function shorten(string $str, int $length = 32, float $position = .75, bool &$sh
/**
* Removes the accents of a string.
*/
function remove_accents(string $str, string $encoding = null): string
function remove_accents(string $str, ?string $encoding = null): string
{
$str = htmlentities($str, ENT_NOQUOTES, $encoding);
$str = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
Expand Down Expand Up @@ -192,7 +192,7 @@ function unaccent_compare_ci(string $a, string $b): int
* @param string $str The string to normalize.
* @param string $separator The separator characters replaces characters the don't match [a-z0-9].
*/
function normalize(string $str, string $separator = '-', string $encoding = null): string
function normalize(string $str, string $separator = '-', ?string $encoding = null): string
{
static $cache;

Expand Down
4 changes: 1 addition & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
executionOrder="depends,defects"
>
<coverage/>
<testsuites>
<testsuite name="icanboogie/common">
<directory>tests</directory>
Expand Down

0 comments on commit b731caa

Please sign in to comment.