Skip to content

Commit

Permalink
Fix PHP 8.4 compatibility
Browse files Browse the repository at this point in the history
Fixes PHP 8.4 compatibility in backwards compatible
fashion. Also updates testing suite to be
compatible with PHP 8.4, but doesn't yet
use it in CI as the run time, but it can
be executed locally.

PHP 8.4 is not released yet, and compatible
xdebug version is not yet available in PECL
repository.

Fixes #227
  • Loading branch information
gocom committed Aug 29, 2024
1 parent 2aa23a5 commit 70137f3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.textile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ h2. Running tests on different PHP versions and platforms
The project comes with multiple different PHP versions that can be used to run the test suite. To run tests on different PHP version, first build the target image and then run tests using it:

bc. $ make docker-build IMAGE=php_8_3
$ make test
$ make test IMAGE=php_8_3

List of available images can be found by running:

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.textile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ h1. Changelog

Here's a summary of changes in each release. The list doesn't include some small changes or updates to test cases.

h2. Version 4.2.0 - upcoming
h2. Version 4.1.2 - upcoming

* Fix PHP 8.4 compatibility issues (closes "#227":https://github.com/textile/php-textile/issues/227).

h2. "Version 4.1.1 - 2024/06/07":https://github.com/textile/php-textile/releases/tag/v4.1.1

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ test-unit: vendor
repl: vendor
$(PHP) composer repl

shell:
$(PHP) bash

bump: vendor
$(PHP) composer project:bump

Expand Down Expand Up @@ -72,6 +75,9 @@ help:
@echo " $$ make repl"
@echo " Launch read-print-eval loop"
@echo ""
@echo " $$ make shell"
@echo " Login into the container"
@echo ""
@echo " $$ make bump"
@echo " Bump version"
@echo ""
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"php": ">=5.3.0"
},
"require-dev": {
"phpstan/phpstan": "1.6.3",
"phpstan/phpstan": "1.12.0",
"phpunit/phpunit": "^9.5.20",
"squizlabs/php_codesniffer": "3.*",
"symfony/yaml": "^4.4.3",
"psy/psysh": "^0.11.2"
"symfony/yaml": "^5.4.40",
"psy/psysh": "^0.12.4"
},
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
"dev-master": "4.1-dev"
}
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- XDEBUG_MODE
- XDEBUG_TRIGGER
- PHP_IDE_CONFIG
- COMPOSER_ROOT_VERSION=dev-master

networks:
app:
Expand Down
12 changes: 12 additions & 0 deletions docker/image/php_8_4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:8.4-rc-cli

RUN apt-get update && apt-get install -y \
bash \
git \
libz-dev \
zip \
wget

COPY --from=composer:2.7 /usr/bin/composer /usr/bin/composer

WORKDIR /app
2 changes: 1 addition & 1 deletion src/Netcarver/Textile/DataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DataBag
*
* @param array<string, string|int>|null $data The initial data array stored in the bag
*/
public function __construct(array $data = null)
public function __construct($data = null)
{
$this->data = (array) $data;
}
Expand Down
23 changes: 14 additions & 9 deletions src/Netcarver/Textile/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class Parser
*
* @var string
*/
protected $ver = '4.2.0-dev';
protected $ver = '4.1.2-dev';

/**
* Regular expression snippets.
Expand Down Expand Up @@ -3039,18 +3039,18 @@ protected function fTextileList($m)

foreach ($list as $index => $m) {
$start = '';
$content = trim($m['content']);
$ltype = $this->liType($m['tl']);
$content = trim((string) $m['content']);
$ltype = $this->liType((string) $m['tl']);

if (isset($list[$index + 1])) {
$next = $list[$index + 1];
} else {
$next = false;
}

if (strpos($m['tl'], ';') !== false) {
if (strpos((string) $m['tl'], ';') !== false) {
$litem = 'dt';
} elseif (strpos($m['tl'], ':') !== false) {
} elseif (strpos((string) $m['tl'], ':') !== false) {
$litem = 'dd';
} else {
$litem = 'li';
Expand Down Expand Up @@ -3080,12 +3080,16 @@ protected function fTextileList($m)
}
}

if ($prev && $prev['tl'] && strpos($prev['tl'], ';') !== false && strpos($m['tl'], ':') !== false) {
if ($prev
&& $prev['tl']
&& strpos((string) $prev['tl'], ';') !== false
&& strpos((string) $m['tl'], ':') !== false
) {
$lists[$m['tl']] = 2;
}

$tabs = str_repeat("\t", $m['level'] - 1);
$atts = $this->parseAttribs($m['atts']);
$tabs = str_repeat("\t", ((int) $m['level']) - 1);
$atts = $this->parseAttribs((string) $m['atts']);

if (!isset($lists[$m['tl']])) {
$lists[$m['tl']] = 1;
Expand Down Expand Up @@ -3760,7 +3764,6 @@ protected function placeNoteLists($text)
ksort($o);
}

// @phpstan-ignore-next-line
$this->notes = $o;
}

Expand Down Expand Up @@ -3955,6 +3958,7 @@ protected function fParseNoteRefs($m)
// If we are referencing a note that hasn't had the definition parsed yet, then assign it an ID.

if (empty($this->notes[$m['label']]['id'])) {
// @phpstan-ignore-next-line
$id = $this->notes[$m['label']]['id'] = $this->linkPrefix . ($this->linkIndex++);
} else {
$id = $this->notes[$m['label']]['id'];
Expand All @@ -3964,6 +3968,7 @@ protected function fParseNoteRefs($m)
$out = '<span id="noteref'.$refid.'">'.$num.'</span>';

if (!$nolink) {
// @phpstan-ignore-next-line
$out = '<a href="#note'.$id.'">'.$out.'</a>';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Netcarver/Textile/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Tag extends DataBag
* @param array<string, int|string> $attributes An array of attributes
* @param bool $selfclosing Whether the tag is self-closing
*/
public function __construct($name, array $attributes = null, $selfclosing = true)
public function __construct($name, $attributes = null, $selfclosing = true)
{
parent::__construct($attributes);
$this->tag = $name;
Expand Down

0 comments on commit 70137f3

Please sign in to comment.