diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index 33888b6..66a1b3d 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -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 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 37f6f81..6a87b5e 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2f14a8..7696156 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,7 @@ jobs: - "8.1" - "8.2" - "8.3" + - "8.4" steps: - name: Checkout uses: actions/checkout@v4 @@ -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: | diff --git a/.gitignore b/.gitignore index 14010f5..4edb3d9 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.phpunit.cache +.phpunit.result.cache build composer.lock vendor diff --git a/Dockerfile b/Dockerfile index b485860..6711544 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile index 0fc5335..528460d 100755 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/docker-compose.yaml b/docker-compose.yaml index 6026526..414b25e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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 diff --git a/lib/OffsetNotDefined.php b/lib/OffsetNotDefined.php index 394ffe9..1393696 100755 --- a/lib/OffsetNotDefined.php +++ b/lib/OffsetNotDefined.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use LogicException; @@ -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)) { diff --git a/lib/OffsetNotReadable.php b/lib/OffsetNotReadable.php index 3a51d86..61146bc 100755 --- a/lib/OffsetNotReadable.php +++ b/lib/OffsetNotReadable.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use LogicException; @@ -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)) { diff --git a/lib/OffsetNotWritable.php b/lib/OffsetNotWritable.php index fb9adec..868c4c2 100755 --- a/lib/OffsetNotWritable.php +++ b/lib/OffsetNotWritable.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use LogicException; @@ -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)) { diff --git a/lib/PropertyError.php b/lib/PropertyError.php index ec06e1b..02bb221 100755 --- a/lib/PropertyError.php +++ b/lib/PropertyError.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use Throwable; diff --git a/lib/PropertyIsReserved.php b/lib/PropertyIsReserved.php index 2992faf..8bc3445 100755 --- a/lib/PropertyIsReserved.php +++ b/lib/PropertyIsReserved.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use LogicException; @@ -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", diff --git a/lib/PropertyNotDefined.php b/lib/PropertyNotDefined.php index 8f52f36..b115c72 100755 --- a/lib/PropertyNotDefined.php +++ b/lib/PropertyNotDefined.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use LogicException; @@ -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'", diff --git a/lib/PropertyNotReadable.php b/lib/PropertyNotReadable.php index 13b7a85..2909d8d 100755 --- a/lib/PropertyNotReadable.php +++ b/lib/PropertyNotReadable.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use LogicException; @@ -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.", diff --git a/lib/PropertyNotWritable.php b/lib/PropertyNotWritable.php index 39ee937..a043b46 100755 --- a/lib/PropertyNotWritable.php +++ b/lib/PropertyNotWritable.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie; use LogicException; @@ -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", diff --git a/lib/array.php b/lib/array.php index 52d0731..e4da942 100644 --- a/lib/array.php +++ b/lib/array.php @@ -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); @@ -140,8 +140,13 @@ function sort_by_weight(array $array, callable $weight_picker): array * * @return array */ -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]); } diff --git a/lib/string.php b/lib/string.php index 9ad4250..234bc5b 100755 --- a/lib/string.php +++ b/lib/string.php @@ -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); } @@ -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); } @@ -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); @@ -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); @@ -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; diff --git a/phpunit.xml b/phpunit.xml index cb3471a..67bfa44 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,17 +1,15 @@ - tests