Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github actions: added a rexstan job #5629

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,44 @@ jobs:

- name: Run phpstan analysis
run: vendor/bin/phpstan analyse --ansi

rexstan-analysis:
name: rexstan static code analysis
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write # for Git to git apply

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: gd, intl, imagick, pdo_mysql
coverage: none # disable xdebug, pcov

- name: Composer install
uses: ramsey/composer-install@v2
with:
composer-options: --ansi --prefer-dist

- name: Setup REDAXO
run: |
sudo /etc/init.d/mysql start
mysql -uroot -h127.0.0.1 -proot -e 'create database redaxo5;'
php redaxo/bin/console setup:run -n --lang=de_de --db-host=127.0.0.1 --db-name=redaxo5 --db-password=root --db-createdb=no --db-setup=normal --admin-username=admin --admin-password=adminpassword --error-email=test@redaxo.invalid --ansi
php redaxo/bin/console config:set --type boolean debug.enabled true
php redaxo/bin/console config:set --type boolean debug.throw_always_exception true

- name: Download & install rexstan
run: |
php redaxo/bin/console install:download rexstan '^1'
php redaxo/bin/console package:install rexstan
php redaxo/bin/console package:activate rexstan
php .tools/phpstan/rexstan.php

- name: Run rexstan analysis
run: php redaxo/bin/console rexstan:analyze
44 changes: 44 additions & 0 deletions .tools/phpstan/rexstan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* boot redaxo and load packages
* necessary to use \rexstan\RexStanUserConfig::save()
*/
unset($REX);
$REX['REDAXO'] = true;
$REX['HTDOCS_PATH'] = './';
$REX['BACKEND_FOLDER'] = 'redaxo';
$REX['LOAD_PAGE'] = false;

require './redaxo/src/core/boot.php';
require './redaxo/src/core/packages.php';

$extensions = [
'../../../../redaxo/src/addons/rexstan/config/rex-superglobals.neon',
'../../../../redaxo/src/addons/rexstan/vendor/phpstan/phpstan/conf/bleedingEdge.neon',
'../../../../redaxo/src/addons/rexstan/vendor/phpstan/phpstan-strict-rules/rules.neon',
'../../../../redaxo/src/addons/rexstan/vendor/phpstan/phpstan-deprecation-rules/rules.neon',
'../../../../redaxo/src/addons/rexstan/config/phpstan-phpunit.neon',
'../../../../redaxo/src/addons/rexstan/config/phpstan-dba.neon',
'../../../../redaxo/src/addons/rexstan/config/cognitive-complexity.neon',
'../../../../redaxo/src/addons/rexstan/config/code-complexity.neon',
'../../../../redaxo/src/addons/rexstan/config/dead-code.neon'
];

$paths = [
'../../../../redaxo/src/core',
'../../../../redaxo/src/addons/backup',
'../../../../redaxo/src/addons/be_style',
'../../../../redaxo/src/addons/cronjob',
'../../../../redaxo/src/addons/debug',
'../../../../redaxo/src/addons/install',
'../../../../redaxo/src/addons/media_manager',
'../../../../redaxo/src/addons/mediapool',
'../../../../redaxo/src/addons/metainfo',
'../../../../redaxo/src/addons/phpmailer',
'../../../../redaxo/src/addons/project',
'../../../../redaxo/src/addons/structure',
'../../../../redaxo/src/addons/users',
];

// creates a basic phpstan config file with all extensions
\rexstan\RexStanUserConfig::save(6, $paths, $extensions, 80115);
2 changes: 1 addition & 1 deletion redaxo/src/addons/backup/lib/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
/**
* @param self::IMPORT_* $importType
*/
public static function isFilenameValid(int $importType, string $filename): bool
public static function isFilenameValid(int $importType, int $filename): bool
{
if (self::IMPORT_ARCHIVE === $importType) {
return str_ends_with($filename, '.tar.gz');

Check failure on line 30 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / phpstan static code analysis

Parameter #1 $haystack of function str_ends_with expects string, int given.

Check failure on line 30 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

InvalidScalarArgument

redaxo/src/addons/backup/lib/backup.php:30:34: InvalidScalarArgument: Argument 1 of str_ends_with expects string, but int provided (see https://psalm.dev/012)
}
if (self::IMPORT_DB === $importType) {
return str_ends_with($filename, '.sql') || str_ends_with($filename, '.sql.gz');

Check failure on line 33 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / phpstan static code analysis

Parameter #1 $haystack of function str_ends_with expects string, int given.

Check failure on line 33 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / phpstan static code analysis

Parameter #1 $haystack of function str_ends_with expects string, int given.

Check failure on line 33 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

InvalidScalarArgument

redaxo/src/addons/backup/lib/backup.php:33:34: InvalidScalarArgument: Argument 1 of str_ends_with expects string, but int provided (see https://psalm.dev/012)

Check failure on line 33 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

TypeDoesNotContainType

redaxo/src/addons/backup/lib/backup.php:33:56: TypeDoesNotContainType: Cannot resolve types for $filename - int does not contain non-empty-string (see https://psalm.dev/056)

Check failure on line 33 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

InvalidScalarArgument

redaxo/src/addons/backup/lib/backup.php:33:70: InvalidScalarArgument: Argument 1 of str_ends_with expects string, but int provided (see https://psalm.dev/012)
}

throw new rex_exception('unexpected importType ' . $importType);
Expand All @@ -51,7 +51,7 @@
foreach ($folder as $file) {
$file = $file->getFilename();
if (is_int($fileType)) {
if (self::isFilenameValid($fileType, $file)) {

Check failure on line 54 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / phpstan static code analysis

Parameter #2 $filename of static method rex_backup::isFilenameValid() expects int, string given.

Check failure on line 54 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

InvalidScalarArgument

redaxo/src/addons/backup/lib/backup.php:54:54: InvalidScalarArgument: Argument 2 of rex_backup::isFilenameValid expects int, but string provided (see https://psalm.dev/012)
$filtered[] = $file;
}
} else {
Expand Down Expand Up @@ -87,7 +87,7 @@
return ['state' => false, 'message' => $message];
};

if ('' == $filename || !self::isFilenameValid(self::IMPORT_DB, $filename)) {

Check failure on line 90 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / phpstan static code analysis

Parameter #2 $filename of static method rex_backup::isFilenameValid() expects int, string given.

Check failure on line 90 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

InvalidScalarArgument

redaxo/src/addons/backup/lib/backup.php:90:72: InvalidScalarArgument: Argument 2 of rex_backup::isFilenameValid expects int, but non-empty-string provided (see https://psalm.dev/012)
return $returnError(rex_i18n::msg('backup_no_import_file_chosen_or_wrong_version') . '<br>');
}

Expand Down Expand Up @@ -216,7 +216,7 @@
$return = [];
$return['state'] = false;

if ('' == $filename || !self::isFilenameValid(self::IMPORT_ARCHIVE, $filename)) {

Check failure on line 219 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / phpstan static code analysis

Parameter #2 $filename of static method rex_backup::isFilenameValid() expects int, string given.

Check failure on line 219 in redaxo/src/addons/backup/lib/backup.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

InvalidScalarArgument

redaxo/src/addons/backup/lib/backup.php:219:77: InvalidScalarArgument: Argument 2 of rex_backup::isFilenameValid expects int, but non-empty-string provided (see https://psalm.dev/012)
$return['message'] = rex_i18n::msg('backup_no_import_file_chosen') . '<br />';
return $return;
}
Expand Down
Loading