Skip to content

Commit 668fc22

Browse files
committed
Fix new static analysis issues and add PHP 8.4, 8.5 & 8.6 to GitHub Actions
1 parent 8975f4e commit 668fc22

12 files changed

Lines changed: 154 additions & 33 deletions

File tree

.github/workflows/php-codestyle.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ jobs:
1414

1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@v4
18-
17+
uses: actions/checkout@v6
18+
1919
- name: Setup PHP
2020
uses: shivammathur/setup-php@v2
2121
with:
2222
php-version: 7.4
2323
extensions: gd,intl,mbstring,sqlite,zip
24-
coverage: disable
24+
coverage: none
2525

26-
- run: composer global require squizlabs/php_codesniffer=* --quiet
26+
- run: composer install --no-progress
2727

2828
- name: PHPCS
29-
run: ~/.composer/vendor/bin/phpcs -s
29+
run: composer webtrees-lib:phpcs

.github/workflows/php-staticanalysis.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,45 @@ jobs:
1414
strategy:
1515
matrix:
1616
operating-system: [ubuntu-latest]
17-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
17+
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
1818

1919
runs-on: ${{ matrix.operating-system }}
2020

2121
steps:
2222
- name: Checkout code
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@v6
2424

2525
- name: Setup PHP
2626
uses: shivammathur/setup-php@v2
2727
with:
2828
php-version: ${{ matrix.php-version }}
2929
extensions: gd,intl,mbstring,sqlite,zip
30-
coverage: disable
30+
coverage: none
3131

32-
- run: composer install --no-progress --no-suggest --ignore-platform-reqs
32+
- run: composer install --no-progress --ignore-platform-reqs
3333

34-
- run: ./vendor-bin/phpstan/vendor/bin/phpstan analyze --no-progress --error-format=github
34+
- run: composer webtrees-lib:phpstan
3535

3636
psalm:
3737
name: psalm - PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }}
3838

3939
strategy:
4040
matrix:
4141
operating-system: [ubuntu-latest]
42-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
42+
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
4343

4444
runs-on: ${{ matrix.operating-system }}
4545

4646
steps:
4747
- name: Checkout code
48-
uses: actions/checkout@v4
48+
uses: actions/checkout@v6
4949

5050
- name: Setup PHP
5151
uses: shivammathur/setup-php@v2
5252
with:
5353
php-version: ${{ matrix.php-version }}
5454
extensions: gd,intl,mbstring,sqlite,zip
55-
coverage: disable
55+
coverage: none
5656

5757
- run: composer global require vimeo/psalm
5858

.github/workflows/php-tests.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
operating-system: [ubuntu-latest]
18-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
18+
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
1919

2020
runs-on: ${{ matrix.operating-system }}
2121

@@ -26,15 +26,16 @@ jobs:
2626
extensions: gd,intl,mbstring,sqlite,zip
2727
coverage: pcov
2828

29-
- uses: actions/checkout@v4
29+
- uses: actions/checkout@v6
3030

3131
- run: composer validate
3232

3333
- run: composer install --no-progress
3434

35-
- run: vendor/bin/phpunit --coverage-clover=tests/coverage.xml
35+
- run: composer webtrees-lib:coverage
3636

37-
- uses: codecov/codecov-action@v3
37+
- uses: codecov/codecov-action@v5
3838
with:
39+
token: ${{ secrets.CODECOV_TOKEN }}
3940
file: tests/coverage.xml
4041
flags: unittests

app/Module/AdminTasks/Services/TokenService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ public function generateRandomToken(int $length = 32): string
4242

4343
# Run each chunk through md5
4444
for ($i = 1; $i <= $chunks; $i++) {
45-
$md5token .= md5(substr($token, $i * 32 - 32, 32));
45+
$chunk = substr($token, $i * 32 - 32, 32);
46+
$md5token .= md5($chunk === false ? '' : $chunk);
4647
}
4748

4849
# Trim the token to the required length
49-
return substr($md5token, 0, $length);
50+
$token_trimmed = substr($md5token, 0, $length);
51+
return $token_trimmed === false ? '' : $token_trimmed;
5052
}
5153
}

app/Module/Hooks/Services/HookService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function all(bool $include_disabled = false): Collection
9898
$hook_info = $hooks_info->get($hook_collector->name()) ?? collect();
9999
foreach (
100100
$hook_instances->filter(
101-
fn(HookInterface $hook): bool => $hook instanceof $hook_interface
101+
fn(HookInterface $hook): bool => $hook instanceof ((string)$hook_interface)
102102
) as $hook_instance
103103
) {
104104
$hook_module_info = $hook_info->get($hook_instance->module()->name(), collect())->first();

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@
8282
]
8383
},
8484
"scripts": {
85-
"webtrees-lib:phpcs" : "phpcs -s",
86-
"webtrees-lib:phpcbf" : "phpcbf",
87-
"webtrees-lib:phpstan" : "./vendor-bin/phpstan/vendor/bin/phpstan analyze",
85+
"webtrees-lib:phpcs" : "./vendor-bin/php-cs/vendor/bin/phpcs -s --exclude=Generic.Files.LineEndings",
86+
"webtrees-lib:phpcbf" : "./vendor-bin/php-cs/vendor/bin/phpcbf --exclude=Generic.Files.LineEndings",
87+
"webtrees-lib:phpstan" : "./vendor-bin/phpstan/vendor/bin/phpstan analyze --no-progress",
8888
"webtrees-lib:sonar" : "sonar-scanner",
89-
"webtrees-lib:test": "phpunit",
90-
"webtrees-lib:coverage": "phpunit --coverage-clover=tests/coverage.xml --coverage-html=tests/coverage"
89+
"webtrees-lib:test": "./vendor/bin/phpunit",
90+
"webtrees-lib:coverage": "./vendor/bin/phpunit --coverage-clover=tests/coverage.xml --coverage-html=tests/coverage"
9191
},
9292
"extra": {
9393
"bamarni-bin": {

composer.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns="https://getpsalm.org/schema/config"
88
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
99
reportMixedIssues="false"
10+
findUnusedCode="false"
1011
errorBaseline="psalm.baseline.xml"
1112
>
1213
<projectFiles>
@@ -29,14 +30,10 @@
2930
<referencedConstant name="MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers\AutoCompleteFile::CACHE_LIFE" />
3031
</errorLevel>
3132
</InvalidClassConstantType>
32-
<InvalidArgument>
33-
<errorLevel type="suppress">
34-
<referencedFunction name="Illuminate\Database\Query\Builder::groupBy" />
35-
</errorLevel>
36-
</InvalidArgument>
3733
<TooManyArguments>
3834
<errorLevel type="suppress">
3935
<referencedFunction name="Illuminate\Database\Query\Builder::select" />
36+
<referencedFunction name="ReflectionMethod::invoke" />
4037
</errorLevel>
4138
</TooManyArguments>
4239
<PropertyNotSetInConstructor>

tests/helpers/TestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace MyArtJaub\Tests\Helpers\Webtrees;
1616

1717
use Fisharebest\Webtrees\View;
18+
use Exception;
1819

1920
/**
2021
* MyArtJaub base class for unit tests
@@ -44,4 +45,15 @@ public static function useDefaultViewFor(string $view): void
4445
View::registerNamespace('maj-common', __DIR__ . '/../resources/views/common/');
4546
View::registerCustomView($view, 'maj-common::default');
4647
}
48+
49+
/**
50+
* Provides an error handler converting PHP errors to exceptions.
51+
*/
52+
public static function errorToExceptionHandler(): callable
53+
{
54+
return static function (int $errno, string $errstr) {
55+
restore_error_handler();
56+
throw new Exception($errstr, $errno);
57+
};
58+
}
4759
}

tests/unit/Module/Certificates/CertificatesModuleTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace MyArtJaub\Tests\Unit\Webtrees\Module\Certificates;
44

55
use Fisharebest\Webtrees\Auth;
6-
use Fisharebest\Webtrees\TestCase;
76
use Fisharebest\Webtrees\Tree;
87
use Fisharebest\Webtrees\User;
98
use Fisharebest\Webtrees\Contracts\UserInterface;
109
use Fisharebest\Webtrees\Services\UserService;
10+
use MyArtJaub\Tests\Helpers\Webtrees\TestCase;
1111
use MyArtJaub\Webtrees\Module\Certificates\CertificatesModule;
12+
use Exception;
1213

1314
/**
1415
* Class CertificatesModuleTest.
@@ -53,6 +54,9 @@ public function testMetadata(): void
5354

5455
public function testHeadContent(): void
5556
{
57+
set_error_handler(self::errorToExceptionHandler(), E_WARNING);
58+
59+
self::expectException(Exception::class);
5660
self::expectExceptionMessageMatches('/filemtime\(\): stat failed/');
5761
self::assertNotEmpty($this->certificates_module->headContent());
5862
}

0 commit comments

Comments
 (0)