Skip to content

Commit 70137f3

Browse files
committed
Fix PHP 8.4 compatibility
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
1 parent 2aa23a5 commit 70137f3

File tree

9 files changed

+43
-17
lines changed

9 files changed

+43
-17
lines changed

.github/CONTRIBUTING.textile

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ h2. Running tests on different PHP versions and platforms
5151
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:
5252

5353
bc. $ make docker-build IMAGE=php_8_3
54-
$ make test
54+
$ make test IMAGE=php_8_3
5555

5656
List of available images can be found by running:
5757

CHANGELOG.textile

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ h1. Changelog
22

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

5-
h2. Version 4.2.0 - upcoming
5+
h2. Version 4.1.2 - upcoming
6+
7+
* Fix PHP 8.4 compatibility issues (closes "#227":https://github.com/textile/php-textile/issues/227).
68

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

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ test-unit: vendor
2929
repl: vendor
3030
$(PHP) composer repl
3131

32+
shell:
33+
$(PHP) bash
34+
3235
bump: vendor
3336
$(PHP) composer project:bump
3437

@@ -72,6 +75,9 @@ help:
7275
@echo " $$ make repl"
7376
@echo " Launch read-print-eval loop"
7477
@echo ""
78+
@echo " $$ make shell"
79+
@echo " Login into the container"
80+
@echo ""
7581
@echo " $$ make bump"
7682
@echo " Bump version"
7783
@echo ""

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
"php": ">=5.3.0"
2424
},
2525
"require-dev": {
26-
"phpstan/phpstan": "1.6.3",
26+
"phpstan/phpstan": "1.12.0",
2727
"phpunit/phpunit": "^9.5.20",
2828
"squizlabs/php_codesniffer": "3.*",
29-
"symfony/yaml": "^4.4.3",
30-
"psy/psysh": "^0.11.2"
29+
"symfony/yaml": "^5.4.40",
30+
"psy/psysh": "^0.12.4"
3131
},
3232
"extra": {
3333
"branch-alias": {
34-
"dev-master": "4.2-dev"
34+
"dev-master": "4.1-dev"
3535
}
3636
},
3737
"scripts": {

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
- XDEBUG_MODE
1414
- XDEBUG_TRIGGER
1515
- PHP_IDE_CONFIG
16+
- COMPOSER_ROOT_VERSION=dev-master
1617

1718
networks:
1819
app:

docker/image/php_8_4/Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM php:8.4-rc-cli
2+
3+
RUN apt-get update && apt-get install -y \
4+
bash \
5+
git \
6+
libz-dev \
7+
zip \
8+
wget
9+
10+
COPY --from=composer:2.7 /usr/bin/composer /usr/bin/composer
11+
12+
WORKDIR /app

src/Netcarver/Textile/DataBag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class DataBag
6464
*
6565
* @param array<string, string|int>|null $data The initial data array stored in the bag
6666
*/
67-
public function __construct(array $data = null)
67+
public function __construct($data = null)
6868
{
6969
$this->data = (array) $data;
7070
}

src/Netcarver/Textile/Parser.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class Parser
384384
*
385385
* @var string
386386
*/
387-
protected $ver = '4.2.0-dev';
387+
protected $ver = '4.1.2-dev';
388388

389389
/**
390390
* Regular expression snippets.
@@ -3039,18 +3039,18 @@ protected function fTextileList($m)
30393039

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

30453045
if (isset($list[$index + 1])) {
30463046
$next = $list[$index + 1];
30473047
} else {
30483048
$next = false;
30493049
}
30503050

3051-
if (strpos($m['tl'], ';') !== false) {
3051+
if (strpos((string) $m['tl'], ';') !== false) {
30523052
$litem = 'dt';
3053-
} elseif (strpos($m['tl'], ':') !== false) {
3053+
} elseif (strpos((string) $m['tl'], ':') !== false) {
30543054
$litem = 'dd';
30553055
} else {
30563056
$litem = 'li';
@@ -3080,12 +3080,16 @@ protected function fTextileList($m)
30803080
}
30813081
}
30823082

3083-
if ($prev && $prev['tl'] && strpos($prev['tl'], ';') !== false && strpos($m['tl'], ':') !== false) {
3083+
if ($prev
3084+
&& $prev['tl']
3085+
&& strpos((string) $prev['tl'], ';') !== false
3086+
&& strpos((string) $m['tl'], ':') !== false
3087+
) {
30843088
$lists[$m['tl']] = 2;
30853089
}
30863090

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

30903094
if (!isset($lists[$m['tl']])) {
30913095
$lists[$m['tl']] = 1;
@@ -3760,7 +3764,6 @@ protected function placeNoteLists($text)
37603764
ksort($o);
37613765
}
37623766

3763-
// @phpstan-ignore-next-line
37643767
$this->notes = $o;
37653768
}
37663769

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

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

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

src/Netcarver/Textile/Tag.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Tag extends DataBag
8383
* @param array<string, int|string> $attributes An array of attributes
8484
* @param bool $selfclosing Whether the tag is self-closing
8585
*/
86-
public function __construct($name, array $attributes = null, $selfclosing = true)
86+
public function __construct($name, $attributes = null, $selfclosing = true)
8787
{
8888
parent::__construct($attributes);
8989
$this->tag = $name;

0 commit comments

Comments
 (0)